FIGURES Module
This module contains a series of functions to make plots of various nature.
- klassez.figures.ax1D(ax, ppm, datax, norm=False, xlims=None, ylims=None, c='tab:blue', lw=0.5, X_label='$\\delta\\ $ F1 /ppm', Y_label='Intensity /a.u.', n_xticks=10, n_yticks=10, label=None, fontsize=10)[source]
Makes the figure of a 1D NMR spectrum, placing it in a given figure panel. This allows the making of modular figures.
The plot can be customized in a very flexible manner by setting the function keywords properly.
- Parameters:
- axmatplotlib.subplot Object
panel where to put the figure
- ppm1darray
ppm scale of the spectrum
- datax1darray
spectrum to be plotted
- normbool
if True, normalizes the intensity to 1.
- xlimslist or tuple
Limits for the x-axis. If None, the whole scale is used.
- ylimslist or tuple
Limits for the y-axis. If None, the whole scale is used.
- cstr
Colour of the line.
- lwfloat
linewidth
- X_labelstr
text of the x-axis label;
- Y_labelstr
text of the y-axis label;
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- n_yticksint
Number of numbered ticks on the x-axis of the figure
- labelstr
label to be put in the legend.
- fontsizefloat
Biggest font size in the figure.
- Returns:
- lineLine2D Object
Line object returned by
plt.plot.
- klassez.figures.ax2D(ax, ppm_f2, ppm_f1, datax, xlims=None, ylims=None, cmap='Greys_r', c_fac=1.4, lvl=0.1, lw=0.5, X_label='$\\delta\\,$F2 /ppm', Y_label='$\\delta\\,$F1 /ppm', title=None, n_xticks=10, n_yticks=10, fontsize=10)[source]
Makes a 2D contour plot like the one in
klassez.figures.figure2D(), but in a specified panel. Allows for the buildup of modular figures. The contours are drawn according to the formula:cl = contour_start * contour_factor ** np.arange(contour_num)
where
contour_start = np.max(data) * lvl,contour_num = 16andcontour_factor = c_fac. Increasing the value ofc_facwill decrease the number of contour lines, whereas decreasing the value ofc_facwill increase the number of contour lines.- Parameters:
- axmatplotlib.Subplot Object
panel where to put the figure
- ppm_f21darray
ppm scale of the direct dimension
- ppm_f11darray
ppm scale of the indirect dimension
- datax2darray
the 2D NMR spectrum to be plotted
- xlimstuple
limits for the x-axis (left, right). If None, the whole scale is used.
- ylimstuple
limits for the y-axis (left, right). If None, the whole scale is used.
- cmapstr
Colormap identifier for the contour (must be in
klassez.CM, or better inklassez.CM_2D)- c_facfloat
Contour factor parameter
- lvlfloat
relative height with respect to maximum at which the contour are computed
- X_labelstr
text of the x-axis label;
- Y_labelstr
text of the y-axis label;
- lwfloat
linewidth of the contours
- cmapnegstr or None
Colormap identifier for the negative contour. If None, they are not computed at all
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- n_yticksint
Number of numbered ticks on the x-axis of the figure
- fontsizefloat
Biggest font size in the figure.
- Returns:
- cntmatplotlib.QuadContour object
Drawn contour lines
See also
- klassez.figures.ax_diffplot(axd, axy, ppm, spectrum, dic, color='tab:blue', fmt='o', ms=8, X_label='$\\delta\\,$ F1 /ppm')[source]
Makes a plot of the diffusion coefficients, with error bars, as a function of the integrated regions.
- Parameters:
- axdmatplotlib.Subplot Object
Subplot for the plot of the diffusion coefficients
- axymatplotlib.Subplot Object or None
Subplot for the plot of the spectra. If
None, it is not drawn.- ppm1darray
ppm scale of the fitted DOSY spectrum
- spectrum2darray
DOSY spectrum
- diclist of dict
Dictionary that comes from the
klassez.fit.DosyFitclass, i.e. from reading a .dy file.- colorstr
Color for the markers that identify the diffusion coefficient
- fmtstr
Marker used
- msint
Marker size
- X_labelstr
Label for the chemical shift axis
- Returns:
- None
- klassez.figures.ax_heatmap(ax, data, zlim='auto', z_sym=True, cmap=None, xscale=None, yscale=None, rev=(False, False), n_xticks=10, n_yticks=10, n_zticks=10, fontsize=10)[source]
Computes a heatmap of data on the given
ax.- Parameters:
- axmatplotlib.Subplot object
Panel where to draw the heatmap
- data2darray
Input data
- zlimtuple or ‘auto’ or ‘abs’
Vertical limits of the heatmap, that determines the extent of the colorbar.
'auto'means(min(data), max(data)),'abs'means(min(|data|), max(|data|)).- z_symbool
True to symmetrize the vertical scale around 0.
- cmapmatplotlib.cm object
Colormap of the heatmap.
- xscale1darray or None
x-scale. None means
np.arange(data.shape[1])- yscale1darray or None
y-scale. None means
np.arange(data.shape[0])- revtuple of bool
Reverse scale (x, y).
- n_xticksint
Number of ticks of the x axis
- n_yticksint
Number of ticks of the y axis
- n_zticksint
Number of ticks of the color bar
- fontsizefloat
Biggest font size to apply to the figure according to
klassez.misc.set_fontsizes()
- Returns:
- immatplotlib.AxesImage
The heatmap
- caxmatplotlib.Subplot object
figure panel where the colorbar is drawn
- klassez.figures.diffplot(ppm, spectrum, dic, xlims=None, color='tab:blue', X_label='$\\delta\\,$ F1 /ppm', filename=None, ext='svg', dpi=300, dim=None)[source]
Makes a plot of the diffusion coefficients, with error bars, as a function of the integrated regions.
- Parameters:
- ppm1darray
ppm scale of the fitted DOSY spectrum
- spectrum2darray
DOSY spectrum
- diclist of dict
Dictionary that comes from the
klassez.fit.DosyFitclass, i.e. from reading a .dy file.- xlimssequence of float or False or None
Limits for the chemical shift axis. If
False, the whole spectrum is plotted. IfNone, a restricted portion of the spectrum which includes all the fitted regions is shown instead- X_labelstr
Label for the chemical shift axis
- filenamestr or None
Filename for the figure to save. If None, the plot is shown instead
- extstr
Format for the figure to save
- dpiint
Resolution of the figure in dots per inches
- dimtuple of int
Dimension of the figure in inches
- Returns:
- None
- klassez.figures.dotmd(ppmscale, S, labels=None, lw=0.8, n_xticks=10, rev=True)[source]
Interactive display of multiple 1D spectra.
- Parameters:
- ppmscale1darray or list of 1darray
ppm scale of the spectra. If only one scale is supplied, all the spectra are plotted using the same scale. Otherwise, each spectrum is plotted using its scale.
- Slist of 1darray
spectra to be plotted
- labelslist
labels to be put in the legend.
- lwfloat
Linewidth of the spectra plots
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- revbool
When
True, the x-scale goes from maximum (left) to minimum (right)
- Returns:
- scale_factor: list
Intensity of the spectra with respect to the original when the figure is closed
- klassez.figures.dotmd_2D(ppm_f1, ppm_f2, S0, labels=None, name='dotmd_2D', X_label='$\\delta\\ $ F2 /ppm', Y_label='$\\delta\\ $ F1 /ppm', n_xticks=10, n_yticks=10, Neg=False)[source]
Interactive display of multiple 2D spectra.
- Parameters:
- ppm_f11darray
ppm scale of the indirect dimension. If only one scale is supplied, all the spectra are plotted using the same scale. Otherwise, each spectrum is plotted using its scale. There is a 1:1 correspondance between
ppm_f1andS.- ppm_f21darray
ppm scale of the direct dimension. If only one scale is supplied, all the spectra are plotted using the same scale. Otherwise, each spectrum is plotted using its scale. There is a 1:1 correspondance between
ppm_f2andS.- Slist
spectra to be plotted
- labelslist
labels to be put in the legend.
- namestr
If you choose to save the figure, this is its filename.
- X_labelstr
text of the x-axis label;
- Y_labelstr
text of the y-axis label;
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- n_yticksint
Number of numbered ticks on the x-axis of the figure
- Negbool
If True, show the negative contours.
- Returns:
- lvllist
Start of level curves of all the spectra when the figure is closed
- klassez.figures.draw_bare_contour(ax, xscale, yscale, data, lvl, cmap='Greys_r', c_fac=1.4, c_num=16, lw=0.5)[source]
Typically used within other functions, this calculates the contour lines and draws them on a given subplot.
- Parameters:
- axmatplotlib.Subplot Object
Panel where to draw the contours
- xscale1darray
X-scale of the contours
- yscale1darray
Y-scale of the contours
- data2darray
Data where to extract the contour levels from
- lvlfloat
Relative height with respect to
datafor the first contour- c_facfloat
Spacing between next contour lines
- c_numint
Number of contour lines to compute
- lwfloat
Linewidths for the contours
- cmapstr
Colormap identifier for the contour (must be in
klassez.CM, or better inklassez.CM_2D)
- Returns:
- cntmatplotlib.contour.QuadContourSet object
Contour levels set
- klassez.figures.figure1D(ppm, datax, norm=False, xlims=None, ylims=None, c='tab:blue', lw=0.5, X_label='$\\delta\\ $ F1 /ppm', Y_label='Intensity /a.u.', n_xticks=10, n_yticks=10, fontsize=10, name=None, ext='svg', dpi=600)[source]
Makes the figure of a 1D NMR spectrum.
The plot can be customized in a very flexible manner by setting the function keywords properly.
- Parameters:
- ppm1darray
ppm scale of the spectrum
- datax1darray
spectrum to be plotted
- normbool
if True, normalizes the intensity to 1.
- xlimslist or tuple
Limits for the x-axis. If None, the whole scale is used.
- ylimslist or tuple
Limits for the y-axis. If None, the whole scale is used.
- cstr
Colour of the line.
- lwfloat
linewidth
- X_labelstr
text of the x-axis label;
- Y_labelstr
text of the y-axis label;
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- n_yticksint
Number of numbered ticks on the x-axis of the figure
- fontsizefloat
Biggest font size in the figure.
- namestr or None
Filename for the figure to be saved. If None, the figure is shown instead.
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- klassez.figures.figure1D_multi(ppm0, data0, xlims=None, ylims=None, norm=False, c=None, lw=0.5, X_label='$\\delta\\ $ F1 /ppm', Y_label='Intensity /a.u.', n_xticks=10, n_yticks=10, fontsize=10, labels=None, name=None, ext='svg', dpi=600)[source]
Creates the superimposed plot of a series of 1D NMR spectra.
- Parameters:
- ppm0sequence of 1darray or 1darray
ppm scale of the spectra. If only one scale is supplied, it is assumed to be the same for all the spectra
- data0sequence of 1darray
List containing the spectra to be plotted
- xlimstuple or None
Limits for the x-axis. If None, the whole scale is used.
- ylimstuple or None
Limits for the y-axis. If None, they are automatically set.
- normFalse or float or str
If it is False, it does nothing. If it is float, divides all spectra for that number. If it is str(‘#’), normalizes all the spectra to the ‘#’ spectrum (python numbering). If it is whatever else string, normalizes all spectra to themselves.
- ctuple or None
List of the colors to use for the traces. None uses the default ones.
- lwfloat
Linewidth thickness
- X_labelstr
text of the x-axis label
- Y_labelstr
text of the y-axis label
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- n_yticksint
Number of numbered ticks on the x-axis of the figure
- fontsizefloat
Biggest fontsize in the picture
- labelslist or None or False
List of the labels to be shown in the legend. If it is None, the default entries are used (i.e., ‘1, 2, 3,…’). If it is False, the legend is not shown.
- namestr or None
Filename of the figure, if it has to be saved. If it is None, the figure is shown instead.
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- klassez.figures.figure2D(ppm_f2, ppm_f1, datax, xlims=None, ylims=None, cmap='Greys_r', c_fac=1.4, lvl=0.09, X_label='$\\delta\\ $ F2 /ppm', Y_label='$\\delta\\ $ F1 /ppm', lw=0.5, cmapneg=None, n_xticks=10, n_yticks=10, fontsize=10, name=None, ext='svg', dpi=600)[source]
Makes a 2D contour plot. The contours are drawn according to the formula:
cl = contour_start * contour_factor ** np.arange(contour_num)
where
contour_start = np.max(data) * lvl,contour_num = 16andcontour_factor = c_fac. Increasing the value ofc_facwill decrease the number of contour lines, whereas decreasing the value ofc_facwill increase the number of contour lines.- Parameters:
- ppm_f21darray
ppm scale of the direct dimension
- ppm_f11darray
ppm scale of the indirect dimension
- datax2darray
the 2D NMR spectrum to be plotted
- xlimstuple
limits for the x-axis (left, right). If None, the whole scale is used.
- ylimstuple
limits for the y-axis (left, right). If None, the whole scale is used.
- cmapstr
Colormap identifier for the contour (must be in
klassez.CM, or better inklassez.CM_2D)- c_fac: float
Contour factor parameter
- lvlfloat
relative height with respect to maximum at which the contour are computed
- X_labelstr
text of the x-axis label;
- Y_labelstr
text of the y-axis label;
- lwfloat
linewidth of the contours
- cmapnegstr or None
Colormap identifier for the negative contour. If None, they are not computed at all
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- n_yticksint
Number of numbered ticks on the x-axis of the figure
- fontsizefloat
Biggest font size in the figure.
- namestr
Filename for the figure
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- Returns:
- None
See also
- klassez.figures.figure2D_multi(ppm_f2, ppm_f1, datax, xlims=None, ylims=None, lvl='default', c_fac=1.4, Negatives=False, X_label='$\\delta\\ $ F2 /ppm', Y_label='$\\delta\\ $ F1 /ppm', lw=0.5, n_xticks=10, n_yticks=10, labels=None, name=None, ext='svg', dpi=600)[source]
Generates the figure of multiple, superimposed spectra, using
klassez.figures.ax2D().- Parameters:
- ppm_f21darray
ppm scale of the direct dimension
- ppm_f11darray
ppm scale of the indirect dimension
- dataxsequence of 2darray
the 2D NMR spectra to be plotted
- xlimstuple
limits for the x-axis (left, right). If None, the whole scale is used.
- ylimstuple
limits for the y-axis (left, right). If None, the whole scale is used.
- lvl“default” or list
height with respect to maximum at which the contour are computed. If “default”, each spectrum is at 10% of maximum height. Otherwise, each entry of the list corresponds to the contour height of the respective spectrum.
- c_facfloat
Contour factor
- Negativesbool
set it to True if you want to see the negative part of the spectrum
- X_labelstr
text of the x-axis label;
- Y_labelstr
text of the y-axis label;
- lwfloat
linewidth of the contours
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- n_yticksint
Number of numbered ticks on the x-axis of the figure
- labelslist
entries of the legend. If None, the spectra are numbered.
- namestr
Filename for the figure. If None, it is shown instead of saved
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- Returns:
- None
See also
- klassez.figures.heatmap(data, zlim='auto', z_sym=True, cmap=None, xscale=None, yscale=None, rev=(False, False), n_xticks=10, n_yticks=10, n_zticks=10, fontsize=10, filename=None, ext='svg', dpi=300)[source]
Computes a heatmap of data.
- Parameters:
- data: 2darray
Input data
- zlim: tuple or ‘auto’ or ‘abs’
Vertical limits of the heatmap, that determines the extent of the colorbar.
'auto'means(min(data), max(data)),'abs'means(min(|data|), max(|data|)).- z_sym: bool
True to symmetrize the vertical scale around 0.
- cmap: matplotlib.cm object
Colormap of the heatmap.
- xscale: 1darray or None
x-scale. None means
np.arange(data.shape[1])- yscale: 1darray or None
y-scale. None means
np.arange(data.shape[0])- rev: tuple of bool
Reverse scale (x, y).
- n_xticks: int
Number of ticks of the x axis
- n_yticks: int
Number of ticks of the y axis
- n_zticks: int
Number of ticks of the color bar
- fontsize: float
Biggest font size to apply to the figure according to
klassez.misc.set_fontsizes()- filename: str or None
Filename for the figure. Set to None to show the figure.
- extstr
Figure format to be saved.
- dpiint
Resolution of the figure to be saved in dots per inches
- Returns:
- None
See also
- klassez.figures.ongoing_fit(exp, calc, residual, ylims=None, filename=None, ext='svg', dpi=100)[source]
Makes a figure of an ongoing fit. It displays the experimental data and the model, and the residuals in a separate window. The figure can be either saved or shown.
Tip
This function has been designed to be fast at rendering! If you want to save it, use
ext='svg'and low dpi otherwise the writing time to disk becomes too slow.- Parameters:
- exp1darray
Experimental data
- calc1darray
Current model
- residual1darray
Residuals of the fit
- ylimstuple
Optional limits for y-axis
- filenamestr or None
Filename of the figure to be saved. If None, the figure is shown instead
- dpiint
Resolution of the figure in dots per inches
- klassez.figures.plot_1D(x, y, SFO1, name='Spectrum', X_label='$\\delta\\,$ /ppm')[source]
Plots the real part of the spectrum in an interactive panel for inspection.
- Parameters:
- x1darray
PPM (or frequency) scale
- y1darray
Spectrum
- SFO1float
Nucleus Larmor frequency
- namestr
Title for the figure
- X_labelstr
Label for the x axis.
- Returns:
- None
- klassez.figures.plot_2D(x_f1, x_f2, yy, SFO1=1, SFO2=1, Neg=True, lvl0=0.2, name='Spectrum', X_label='$\\delta\\,$F2 /ppm', Y_label='$\\delta\\,$F1 /ppm')[source]
Plots the real part of the spectrum. Use the mouse scroll to adjust the contour starting level.
- Parameters:
- x_f11darray
PPM (or frequency) scale for the y axis
- x_f21darray
PPM (or frequency) scale for the x axis
- yy2darray
Spectrum
- SFO1float
Nucleus Larmor frequency of the indirect dimension
- SFO2float
Nucleus Larmor frequency of the direct dimension
- Negbool
Display also the negative part of the spectrum
- lvl0float
Starting contour level, with respect to the maximum of the spectrum
- namestr
Filename for the figure.
- X_labelstr
Label for the x axis.
- Y_labelstr
Label for the y axis.
- Returns:
- None
- klassez.figures.plot_fid(fid, name=None, ext='svg', dpi=600)[source]
Makes a two-panel figure that shows on the left the real part of the FID, on the right the imaginary part. The x-scale and y-scale are automatically adjusted.
- Parameters:
- fidndarray
FID to be plotted
- namestr
Name of the figure
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- klassez.figures.plot_fid_re(fid, scale=None, c='b', lims=None, name=None, ext='svg', dpi=600)[source]
Makes a single-panel figure that shows either the real or the imaginary part of the FID. The x-scale and y-scale are automatically adjusted.
- Parameters:
- fidndarray
FID to be plotted
- scale1darray or None
x-scale of the figure
- cstr
Color
- limstuple or None
Limits
- namestr
Name of the figure
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- klassez.figures.plot_p3D(x_f1, x_f2, idx_scale, yyy, dim='31', Neg=True, lvl0=0.2, name='', X_label='$\\delta\\,$ /ppm', Y_label='')[source]
Plots the real part of the spectrum. Use the mouse scroll to adjust the contour starting level. Use the ‘<<’ and ‘>>’ to move across planes.
- Parameters:
- x_f11darray
PPM (or frequency) scale for the y axis
- x_f21darray
PPM (or frequency) scale for the x axis
- idx_scale1darray
Scale for the non-directly plotted dimension
- yyy3darray
Spectrum
- dimstr
Slicing direction.
dim = '31'–> Plot planes F3-F1 –>idx_scalerepresent F2dim = '32'–> Plot planes F3-F2 –>idx_scalerepresent F1
- Negbool
Display also the negative part of the spectrum
- lvl0float
Starting contour level, with respect to the maximum of the spectrum
- namestr
Filename for the figure.
- X_labelstr
Label for the x axis.
- Y_labelstr
Label for the y axis.
- Returns:
- None
- klassez.figures.redraw_contours(ax, ppm_f2, ppm_f1, S, lvl, cnt, Neg=False, Ncnt=None, cmap=[None, None], c_fac=1.4, c_num=16, lw=0.5)[source]
Redraws the contours in interactive 2D visualizations.
- Parameters:
- axmatplotlib.Subplot Object
Panel of the figure where to draw the contours
- ppm_f21darray
ppm scale of the direct dimension
- ppm_f11darray
ppm scale of the indirect dimension
- S2darray
Spectrum
- lvlfloat
Level at which to draw the contours
- cntmatplotlib.contour.QuadContourSet object
Pre-existing contours
- Negbool
Choose if to draw the negative contours (True) or not (False)
- Ncntmatplotlib.contour.QuadContourSet object
Pre-existing negative contours
- lwfloat
Linewidth
- cmaplist
Colour of the contours. [cmap +, cmap -]
- Returns:
- cntmatplotlib.contour.QuadContourSet object
Updated contours
- Ncntmatplotlib.contour.QuadContourSet object or None
Updated negative contours if Neg is True, None otherwise
See also
- klassez.figures.sns_heatmap(data, name=None, ext='svg', dpi=600)[source]
Computes a heatmap of
data. This function employs the seaborn package. Specifynameif you want to save the figure.- Parameters:
- data2darray
Data of which to compute the heatmap. Make sure the entries are real numbers.
- namestr or None
Filename of the figure to be saved. If None, the figure is shown instead.
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- klassez.figures.stacked_plot(ppmscale, S, xlims=None, lw=0.5, X_label='$\\delta\\ $ F1 /ppm', Y_label='Normalized intensity /a.u.', n_xticks=10, labels=None, name=None, ext='svg', dpi=600)[source]
Creates a stacked plot of all the spectra contained in the list
S. Note thatSMUST BE a list. All the spectra must share the same scale.- Parameters:
- ppmscale1darray
ppm scale of the spectrum
- Slist of 1darray
spectra to be plotted
- xlimslist or tuple
Limits for the x-axis. If None, the whole scale is used.
- lwfloat
linewidth
- X_labelstr
text of the x-axis label;
- Y_labelstr
text of the y-axis label;
- n_xticksint
Number of numbered ticks on the x-axis of the figure
- labelslist
labels to be put in the legend.
- namestr
filename of the figure, if it has to be saved;
- extstr
Format of the image
- dpiint
Resolution of the image in dots per inches
- Returns:
- None
See also