Plotting Functions

Throughout the toolbox, care has been taken to present results and project analyses into outputs of a form directly interpretable by the analyst, such as projecting the loadings of a multivariate model onto the spectrum in the case of NMR, and as an ion-map for LC-MS.

See the Plot Gallery for a visual overview of the available plots.

The plotting module contains function to generate several common visualisations.

Plots are built upon seaborn for aesthetics, or when interactivity is required, plotly.

Most plots support a set of common configuration parameters to allow customisation of various display options. Common parameters that may be specified as keyword arguments are:

plottingFunctions(*vars, **kwargs):
Parameters:
  • savePath (str) – If None plot interactively, otherwise save the figure to the path specified
  • figureFormat (str) – If saving the plot, use this format
  • dpi (int) – Plot resolution
  • figureSize (tuple(float, float)) – Dimensions of the figure

Interactive plots utilise the plotly framework to provide controls, when using plotly you should ensure that the environment is configured according to the instructions at Offline Plots in Plotly in Python

nPYc.plotting.histogram(values, inclusionVector=None, quantiles=None, histBins=100, color=None, logy=False, logx=False, **kwargs)

Plot a histogram of values, optionally segmented according to observed quantiles.

Quantiles can be calculated on a second inclusionVector when specified.

Parameters:
  • values (numpy.array or dict) – Values to plot
  • inclusionVector (None or numpy.array) – Optional second vector with same size as values, used to select quantiles for plotting.
  • quantiles (None or List) – List of quantile bounds to segment the histogram by
  • title (str) – Title for the plot
  • xlabel (str) – Label for the X-axis
  • histBins (int) – Number of bins to break the histgram into
  • color (None or List) – List of specific colours to use for plotting
  • logy (bool) – If True plot y on a log scale
  • logx (bool) – If True plot x on a log scale
  • xlim (tuple of int) – Specify upper and lower bounds of the X axis
nPYc.plotting.plotBatchAndROCorrection(msData, msDatacorrected, featureList, addViolin=True, sampleAnnotation=None, logy=False, title='', savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Visualise the run-order correction applied to features, by plotting the values before and after correction, along with the fit calculated.

Parameters:
  • msData (MSDataset) – Dataset prior to correction
  • msDatacorrected (MSDataset) – Dataset post-correction
  • featureList (list[int,]) – List of ints specifying indices of features to plot
  • addViolin (bool) – If true, plot distributions as violin plots in addition to the longitudinal trend
  • sampleAnnotation (dict) – Samples for annotation in plot, must include fields ‘rank’: index (int) and ‘id’: sample name (str, as in msData.sampleMetadata[‘Sample File Name’]). For example, item[‘AbundanceSamples’] in featureID.py.
  • logy (bool) – If True plot intensities on a log10 scale
  • title (str) – Text to title each plot with
  • savePath (None or str) – If None plot interactively, otherwise save the figures to the path specified
nPYc.plotting.plotTIC(msData, addViolin=True, addBatchShading=False, addLineAtGaps=False, colourByDetectorVoltage=False, logy=False, title='', withExclusions=True, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Visualise TIC for all or a subset of features coloured by either dilution value or detector voltage. With the option to shade by batch.

Note

addViolin and colourByDetectorVoltage are mutually exclusive.

Parameters:
  • msData (MSDataset) – Dataset object
  • addViolin (bool) – If True adds violin plots of TIC distribution pre and post correction split by sample type
  • addBatchShading (bool) – If True shades plot according to sample batch
  • addLineAtGaps (bool) – If True adds line where acquisition time is greater than double the norm
  • colourByDetectorVoltage (bool) – If True colours points by detector voltage, else colours by dilution
  • logy (bool) – If True plot y on a log scale
  • title (str) – Title for the plot
  • withExclusions (bool) – If False, discard masked features from the sum
  • savePath (None or str) – If None plot interactively, otherwise save the figure to the path specified
  • figureFormat (str) – If saving the plot, use this format
  • dpi (int) – Plot resolution
  • figureSize (tuple(float, float)) – Dimensions of the figure
nPYc.plotting.plotTICinteractive(msData, plottype='Sample Type', labelby='Run Order', withExclusions=True)

Interactively visualise TIC (coloured by batch and sample type) with plotly, provides tooltips to allow identification of samples.

Plots may be of two types: * ‘Sample Type’ to plot by sample type and coloured by batch * ‘Linearity Reference’ to plot LR samples coloured by dilution

Parameters:
  • msData (MSDataset) – Dataset object
  • plottype (str) – Select plot type, may be either Sample Type or Linearity Reference
Returns:

Data object to use with plotly

nPYc.plotting.plotLRTIC(msData, sampleMask=None, colourByDetectorVoltage=False, title='', label=False, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Visualise TIC for linearity reference (LR) samples (either all or a subset) coloured by either dilution value or detector voltage.

Parameters:
  • msData (MSDataset) – Dataset object
  • sampleMask (None or array of bool) – Defines subset of samples to plot, if None use msData’s built-in sampleMask
  • colourByDetectorVoltage (bool) – If True colours points by detector voltage, else colours by dilution
  • title (str) – Title for the plot
  • label (bool) – If True, labels points with run order values
  • savePath (None or str) – If None, plot interactively, otherwise attempt to save at this path.
  • format (str) – Format to save figure
  • dpi (int) – Resolution to draw at
  • figureSize (tuple(float, float)) – Specify size of figure
nPYc.plotting.jointplotRSDvCorrelation(rsd, correlation, histBins=100, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot a 2D histogram of feature RSDs vs correlations to dilution, with marginal histograms.

Parameters:
  • rsd (numpy.array) – Vector of feature relative standard deviations
  • correlation (numpy.array) – Vector of correlation to dilution
  • histBins (int) – Number of bins to break the histgram into
  • savePath (None or str) – If None, plot interactively, otherwise attempt to save at this path
  • figureFormat (str) – If saving the plot, use this format
  • dpi (int) – Plot resolution
  • figureSize (tuple(float, float)) – Dimensions of the figure
nPYc.plotting.plotCorrelationToLRbyFeature(msData, featureMask=None, title='', maxNo=5, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Summary plots of correlation to dilution for a subset of features, separated by sample batch. Each figure includes a scatter plot of feature intensity vs dilution, TIC of LR and surrounding SP samples, and a heatmap of correlation to dilution for each LR batch subset, overall, and mean.

Parameters:
  • msData (MSDataset) – Dataset object
  • featureMask (None or array of bool) – Limits plotting to a subset of features, if None use msData’s built-in sampleMask
  • title (str) – Title for the plot
  • maxNo (int) – Optional number of features to plot (default=10, i.e., 10 randomly selected features in featureList will be plotted)
  • savePath (None or str) – If None, plot interactively, otherwise attempt to save at this path.
  • figureFormat (str) – Format to save figure
  • dpi (int) – Resolution to draw at
  • figureSize (tuple(float, float)) – Specify size of figure
nPYc.plotting.plotIonMap(msData, useRetention=True, title=None, savePath=None, xlim=None, ylim=None, logx=False, logy=False, figureFormat='png', dpi=72, figureSize=(11, 7))

plotIonMap(msData, **kwargs):

Visualise features in a MSDataset, to visualise the features in terms of the raw data.

Plotting requires the presence of ‘m/z’ and ‘Retention Time’ columns in the featureMetadata table. If both ‘m/z’ and retention time are present, a 2D ion map is generated, otherwise a 1D mass-spectrum is plotted.

Parameters:
  • msData (MSDataset) – Dataset object to visualise
  • useRetention (bool) – If False ignore any Retention Time information and plot a 1D mass spectrum
nPYc.plotting.plotRSDs(dataset, ratio=False, savePath=None, color=None **kwargs)

Visualise analytical versus biological variance.

Plot RSDs calculated in study-reference samples (analytical variance), versus those calculated in study samples (biological variance). RSDs can be visualised either in absolute terms, or as a ratio to analytical variation (ratio=True).

plotRSDs() requires that the dataset have at least two samples with the PrecisionReference assay role, if present, RSDs calculated on independent sets of PrecisionReference samples will also be plotted.

Parameters:
  • dataset (Dataset) – Dataset object to plot, the object must have greater that one ‘Study Sample’ and ‘Study-Reference Sample’ defined
  • ratio (bool) – If True plot the ratio of analytical variance to biological variance instead of raw values
  • featureName (str) – featureMetadata column name by which to label features
  • logx (bool) – If True plot RSDs on a log10 scaled axis
  • xlim (None or tuple(float, float)) – Tuple of (min, max) RSD values to plot
  • hLines (None or list) – None or list of y positions at which to plot an horizontal line. Features are positioned from 1 to nFeat
  • savePath (None or str) – If None plot interactively, otherwise save the figure to the path specified
  • color (None or seaborn.palettes._ColorPalette) – Allows the default colour pallet to be overridden
  • featName (bool) – If True y-axis label is the feature Name, if False features are numbered.
nPYc.plotting.plotRSDsInteractive(dataset, featureName='Feature Name', ratio=False, logx=True)

Plotly-based interactive version of plotRSDs()

Visualise analytical versus biological variance.

Plot RSDs calculated in study-reference samples (analytical variance), versus those calculated in study samples (biological variance). RSDs can be visualised either in absolute terms, or as a ratio to analytical variation (ratio=True).

plotRSDsInteractive() requires that the dataset have at least two samples with the PrecisionReference assay role, if present, RSDs calculated on independent sets of PrecisionReference samples will also be plotted.

Parameters:
  • dataset (Dataset) – Dataset object to plot, the object must have greater that one ‘Study Sample’ and ‘Study-Reference Sample’ defined
  • featureName (str) – featureMetadata column name by which to label features
  • ratio (bool) – If True plot the ratio of analytical variance to biological variance instead of raw values
  • logx (bool) – If True plot RSDs on a log10 scaled axis
nPYc.plotting.plotScree(R2, Q2=None, title='', xlabel='', ylabel='', savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot a barchart of variance explained (R2) and predicted (Q2) (if available) for each PCA component.

Parameters:
  • R2 (numpy.array) – PCA R2 values
  • Q2 (numpy.array) – PCA Q2 values
  • title (str) – Title for the plot
  • xlabel (str) – Label for the x-axis
  • ylabel (str) – Label for the y-axis
nPYc.plotting.plotOutliers(values, runOrder, sampleType=None, addViolin=False, Fcrit=None, FcritAlpha=None, PcritPercentile=None, title='', xlabel='Run Order', ylabel='', savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot scatter plot of PCA outlier stats sumT (strong) or DmodX (moderate), with a line at [25, 50, 75, 95, 99] quantiles and at a critical value if specified

Parameters:
  • values (numpy.array) – dModX or sum of scores, measure of ‘fit’ for each sample
  • runOrder (numpy.array) – Order of sample acquisition (samples are plotted in this order)
  • sampleType (pandas.Series) – Sample type of each sample, must be from ‘Study Sample’, ‘Study Reference’, ‘Long-Term Reference’, or ‘Sample’ (see multivariateReport.py)
  • addViolin (bool) – If True adds a violin plot of distribution of values
  • Fcrit (float) – If not none, plots a line at Fcrit
  • FcritAlpha (float) – Alpha value for Fcrit (for legend)
  • PcritPercentile (float) – If not none, plots a line at this quantile
  • title (str) – Title for the plot
  • xlabel (str) – Label for the x-axis
nPYc.plotting.plotSpectralVariance(dataset, classes=None, quantiles=(25, 75), average='median', xlim=None, **kwargs)

Plot the average spectral profile of dataset, optionally with the bounds of variance calculated from quantiles shaded. By specifying a column from dataset.sampleMetadata in the classes argument, individual averages and ranges will be plotted for each unique label in dataset.sampleMetadata[classes].

Parameters:
  • dataset (Dataset) – Data to plot
  • classes (None or column in dataset.sampleMetadata) – Plot by distinct classes specified
  • quantiles (None or (min, max)) – Plot these quantile bounds
  • average (str) – Method to calculate average spectrum, defaults to ‘median’, may also be ‘mean’
  • xlim (None or (float, float)) – Tuple of (min, max) values to scale the x-axis to
  • logy (bool) – If True plot intensities on a log10 scale
  • title (str) – Text to title each plot with
nPYc.plotting.plotScores(pcaModel, classes=None, classType=None, components=None, alpha=0.05, plotAssociation=None, title='', xlabel='', figures=None, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot PCA scores for each pair of components in PCAmodel, coloured by values defined in classes, and with Hotelling’s T2 ellipse (95%)

Parameters:
  • pcaModel (ChemometricsPCA) – PCA model object (scikit-learn based)
  • classes (pandas.Series) – Measurement/groupings associated with each sample, e.g., BMI/treatment status
  • classType (str) – Type of data in classes, either ‘Plot Sample Type’, ‘categorical’ or ‘continuous’, must be specified if classes is not None. If classType is ‘Plot Sample Type’, classes expects ‘Study Sample’, ‘Study Reference’, ‘Long-Term Reference’, ‘Serial Dilution’ or ‘Sample’.
  • components (tuple (int, int)) – If None plots all components in model, else plots those specified in components
  • alpha (float) – Significance value for plotting Hotellings ellipse
  • plotAssociation (bool) – If True, plots the association between each set of PCA scores and the metadata values
  • significance (numpy.array) – Significance of association of scores from each component with values in classes from correlation or Kruskal-Wallis test for example (see multivariateReport.py)
  • title (str) – Title for the plot
  • xlabel (str) – Label for the x-axis
  • figures (dict) – If not None, saves location of each figure for output in html report (see multivariateReport.py)
nPYc.plotting.plotScoresInteractive(dataTrue, pcaModel, colourBy, components=[1, 2], alpha=0.05, withExclusions=False)

Interactively visualise PCA scores (coloured by a given sampleMetadata field, and for a given pair of components) with plotly, provides tooltips to allow identification of samples.

Parameters:
  • dataTrue (Dataset) – Dataset
  • object pcaModel (PCA) – PCA model object (scikit-learn based)
  • colourBy (str) – sampleMetadata field name to of which values to colour samples by
  • components (list) – List of two integers, components to plot
  • alpha (float) – Significance value for plotting Hotellings ellipse
  • withExclusions (bool) – If True, only report on features and samples not masked by the sample and feature masks; must match between data and pcaModel
nPYc.plotting.plotLoadings(pcaModel, msData, title='', figures=None, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot PCA loadings for each component in PCAmodel. For NMR data plots the median spectrum coloured by the loading. For MS data plots an ion map (rt vs. mz) coloured by the loading.

Parameters:
  • pcaModel (ChemometricsPCA) – PCA model object (scikit-learn based)
  • msData (Dataset) – Dataset object
  • title (str) – Title for the plot
  • figures (dict) – If not None, saves location of each figure for output in html report (see multivariateReport.py)
nPYc.plotting.plotLoadingsInteractive(dataTrue, pcaModel, component=1, withExclusions=False)

Interactively visualise PCA loadings (for a given pair of components) with plotly, provides tooltips to allow identification of features.

For MS data, plots RT vs. mz; for NMR plots ppm vs spectral intensity. Plots are coloured by the weight of the loadings.

Parameters:
  • dataTrue (Dataset) – Dataset
  • pcaModel (ChemometricsPCA) – PCA model object (scikit-learn based)
  • component (int) – Component(s) to plot (one component (int) or list of two integers)
  • withExclusions (bool) – If True, only report on features and samples not masked by the sample and feature masks; must match between data and pcaModel
nPYc.plotting.plotDiscreteLoadings(pcaModel, nbComponentPerRow=3, firstComponent=1, sort=True, **kwargs)

Plot loadings for a linear model as a set of parallel vertical scatter plots.

Parameters:
  • pcaModel (ChemometricsPCA) – Model to plot
  • nbComponentPerRow (int) – Number of side-by-side loading plots to place per row
  • firstComponent (int) – Start plotting components from this component
  • sort (bool) – Plot variable in order of their magnitude in component one
nPYc.plotting.plotFeatureRanges(dataset, compounds, logx=False, histBins=20, **kwargs)

Plot distributions plots of the values listed in compounds, on to a set of axes with a linked x-axis.

If reference ranges are specified in featureMetadata, a reference range will be drawn behind each plot. If reference ranges are available, distributions that for within the range will be shaded green, and those that fall outside red, where no reference range is available the distribution will be shaded blue.

Parameters:
  • dataset (Dataset) – Dataset object to plot values from
  • compounds (list) – List of features to plot
  • logx (bool) – Calculate and plot histograms on a log10 scale, if the minumn values is below 1, the histogram is calculated by adding one to all values
  • histBins (int) – Number of bins for histograms
nPYc.plotting.plotMetadataDistribution(sampleMetadata, valueType, figures=None, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot the distribution of a set of data, e.g., sampleMetadata fields. Plots a bar chart for categorical data, or a histogram for continuous data.

Parameters:
  • sampleMetadata (dataset.sampleMetadata) – Set of measurements/groupings associated with each sample, note can contain multiple columns, but they must be of one valueType
  • valueType (str) – Type of data contained in sampleMetadata, one of continuous, categorical or date
  • figures (dict) – If not None, saves location of each figure for output in html report (see multivariateReport.py)
nPYc.plotting.plotLOQRunOrder(targetedData, addCalibration=True, compareBatch=True, title='', savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Visualise ratio of LLOQ and ULOQ by run order, separated by batch. Option to add barchart that summarises across batch

Parameters:
  • targetedData (TargetedDataset) – TargetedDataset object
  • addCalibration (bool) – If True add calibration samples
  • compareBatch (bool) – If True add barchart across batch, separated by SampleType
  • title (str) – Title for the plot
  • savePath (None or str) – If None plot interactively, otherwise save the figure to the path specified
  • figureFormat (str) – If saving the plot, use this format
  • dpi (int) – Plot resolution
  • figureSize (tuple(float, float)) – Dimensions of the figure
Raises:
  • ValueError – if targetedData does not satisfy to the TargetedDataset definition for QC
  • ValueError – if calibration does not match the number of batch
nPYc.plotting.plotFeatureLOQ(tData, splitByBatch=True, plotBatchLOQ=False, zoomLOQ=False, logY=False, tightYLim=True, nbPlotPerRow=3, metabolitesPerPlot=5, withExclusions=True, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Violin plot for each feature with line at LOQ concentrations. Option to split by batch, add each batch LOQs, split by SampleType.

Parameters:
  • tData (TargetedDataset) – TargetedDataset
  • splitByBatch (bool) – If True separate each violin plot by batch
  • plotBatchLOQ (bool) – If True add lines at LOQs (LLOQ/ULOQ) for each batch, and points for samples that will be out of LOQ
  • zoomLOQ (bool) – If True plots a zoomed ULOQ plot on top, all data in the centre and a zoomed LLOQ plot at the bottom
  • logY (bool) – If True log-scale the y-axis
  • tightYLim (bool) – if True ylim are close to the points but can let LOQ lines outside, if False LOQ lines will be part of the plot.
  • nbPlotPerRow (int) – Number of plots to place on each row
  • metabolitesPerPlot (int) – Maximum numper of metabolites to plot in on single figure
  • savePath (None or str) – If None plot interactively, otherwise save the figure to the path specified
  • figureFormat (str) – If saving the plot, use this format
  • dpi (int) – Plot resolution
  • figureSize (tuple(float, float)) – Dimensions of the figure
Raises:

ValueError – if targetedData does not satisfy to the TargetedDataset definition for QC

nPYc.plotting.plotVariableScatter(inputTable, logX=False, xLim=None, xLabel='', yLabel='', sampletypeColor=False, hLines=None, hLineStyle='-', hBox=None, vLines=None, vLineStyle=':', vBox=None, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot values on x-axis, with ordering on the y-axis. Entries as rows are placed on the x-axis, values of all columns are plotted on y-axis with different colors. If sampletypeColor=True, only columns named as SampleTypes will be plotted and colored according to other reports, otherwise all columns are plotted. Ordering of the rows is conserved, the first item is placed at the top of the y-axis and the last row is at the bottom. If a column [‘yName’] is present, it is employed to label each y-axis entry.

Parameters:
  • inputTable (dataframe) – DataFrame or accuracy or precision values, with features as rows and sample types as columns ([‘Study Sample’, ‘Study Pool’, ‘External Reference’, ‘All Samples’, ‘nan’]). A ‘yName’ column can be present to display the feature name.
  • logX (bool) – If True plot values on a log10 scaled x axis
  • xLim (None or tuple(float, float)) – Tuple of (min, max) values to plot
  • xLabel (str) – X-axis label
  • yLabel (str) – Y-axis label
  • sampletypeColor (bool) – If True only the sampleType columns are plotted with colors matching other reports
  • hLines (None or list) – None or list of y positions at which to plot an horizontal line. Features are positioned from 1 to nFeat
  • hLineStyle (str) – One of the axhline linestyle (‘-’, ‘–’, ‘-.’, ‘:’)
  • hBox (None or list) – None or list of tuple of y positions defining horizontal box. Features are positioned from 1 to nFeat
  • vLines (None or list) – None or list of v positions at which to plot an vertical line. Unit is the same as the v axis.
  • vLineStyle (str) – One of the axvline linestyle (‘-’, ‘–’, ‘-.’, ‘:’)
  • vBox (None or list) – None or list of tuple of x positions defining horizontal box. Features are positioned from 1 to nFeat
  • color (None or seaborn.palettes._ColorPalette) – Allows the default colour pallet to be overridden
  • savePath (None or str) – If None plot interactively, otherwise save the figure to the path specified
nPYc.plotting.plotAccuracyPrecision(tData, accuracy=True, percentRange=None, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot Accuracy or Precision for a TargetedDataset.

Features at all present concentrations are shown on the y-axis, with accuracy or precision values on the x-axis. Accuracy are centered around 100%. If Precision values cover too wide a range, x-axis is log transformed.

Parameters:
  • tData (TargetedDataset) – TargetedDataset object to plot
  • accuracy (bool) – If True plot the Accuracy of each measurements, if False plot the Precision of measurements.
  • percentRange (None or float) – If float [0, inf], add a rectangle covering the range of acceptable percentage; for Accuracy 100 +/- percentage, for Precision 0 - percentage.
  • savePath (None or str) – If None plot interactively, otherwise save the figure to the path specified
  • figureFormat (str) – If saving the plot, use this format
  • dpi (int) – Plot resolution
  • figureSize (tuple(float, float)) – Dimensions of the figure
Raises:
  • ValueError – if targetedData does not satisfy to the TargetedDataset definition for QC
  • ValueError – if percentRange is not ‘None’ or float
nPYc.plotting.plotCalibrationInteractive(nmrData)

Build Plotly figure of calibration

Parameters:nmrData (NMRDataset) – Dataset to visualise
Returns:Plotly figure object for displaly with iplot()
Return type:plotly.graph_objs.Figure
nPYc.plotting.plotLineWidth(nmrData, **kwargs)

Visualise spectral line widths, plotting the median spectrum, the 95% variance, and any spectra where line width can not be calulated or exceeds the cutoff specified in nmrData.Attributes['LWpeakRange'].

Parameters:
  • nmrData (NMRDataset) – Dataset object
  • savePath (None or str) – If None, plot interactively, otherwise attempt to save at this path
nPYc.plotting.plotLineWidthInteractive(nmrData)

Interactive Plotly version of py:func:plotLineWidth

Visualise spectral line widths, plotting the median spectrum, the 95% variance, and any spectra where line width can not be calulated or exceeds the cutoff specified in nmrData.Attributes['LWpeakRange'].

Parameters:
  • nmrData (NMRDataset) – Dataset object
  • savePath (None or str) – If None, plot interactively, otherwise attempt to save at this path
nPYc.plotting.plotBaseline(nmrData, savePath=None, **kwargs)

Plot spectral baseline at the high and low end of the spectrum. Visualise the median, bounds of 95% variance, and outliers.

Parameters:
  • nmrData (NMRDataset) – Dataset object
  • savePath (None or str) – If None, plot interactively, otherwise attempt to save at this path
nPYc.plotting.plotBaselineInteractive(nmrData)

Interactive Plotly version of py:func:plotBaseline.

Plot spectral baseline at the high and low end of the spectrum. Visualise the median, bounds of 95% variance, and outliers.

Parameters:nmrData (NMRDataset) – Dataset object
nPYc.plotting.plotSolventResonance(nmrData, **kwargs)

Plot the solvent region to be cut from the spectrum along with spectra failing solvent region checks.

Parameters:
  • nmrData (NMRDataset) – Dataset to plot
  • savePath (None or str) – If None draw interactively, otherwise save to this path
nPYc.plotting.plotSolventResonanceInteractive(nmrData, title='Residual solvent resonance')

Ploty interactive version of plotSolventResonance()

Plot the solvent region to be cut from the spectrum along with spectra failing solvent region checks.

Parameters:nmrData (NMRDataset) – Dataset to plot
Returns:Plotly figure object to plot with iPlot
nPYc.plotting.plotSpectraInteractive(dataset, samples=None, xlim=None, featureNames=None, sampleLabels='Sample ID', nmrDataset=True)

Plot spectra from dataset.

#:param Dataset dataset: Dataset to plot from :param samples: Index of samples to plot, if None plot all spectra :type samples: None or list of int :param xlim: Tuple of (minimum value, maximum value) defining a feature range to plot :type xlim: (float, float)

nPYc.plotting.plotIonMapInteractive(dataset, title=None, xlim=None, ylim=None, logx=False, logy=False, featureName='Feature Name')

Visualise features in a MSDataset, as an ion map.

Plotting requires the presence of ‘m/z’ and ‘Retention Time’ columns in the featureMetadata table.

Parameters:msData (MSDataset) – Dataset object to visualise
nPYc.plotting.plotSpectralVarianceInteractive(dataset, classes=None, quantiles=(25, 75), average='mean', xlim=None, title=None)

Plot the average spectral profile of dataset, optionally with the bounds of variance calculated from quantiles shaded. By specifying a column from dataset.sampleMetadata in the classes argument, individual averages and ranges will be plotted for each unique label in dataset.sampleMetadata[classes].

Parameters:
  • dataset (Dataset) – Data to plot
  • classes (None or column in dataset.sampleMetadata) – Plot by distinct classes specified
  • quantiles (None or (min, max)) – Plot these quantile bounds
  • average (str) – Method to calculate average spectrum, defaults to ‘median’, may also be ‘mean’
  • xlim (None or (float, float)) – Tuple of (min, max) values to scale the x-axis to
nPYc.plotting.correlationSpectroscopyInteractive(dataset, target, mode='SHY', correlationMethod='Pearson')

Conduct correlation spectroscopy analyses against the samples in dataset.

Mode may be one of: - SHY Correlate features in dataset to values in target

Parameters:
  • dataset (Dataset) – Correlations weill be projected into this dataset
  • target (numpy.array) – Correlations are calculated to this
  • mode (str) – Type of analysis to conduct
  • correlationMethod (str) – Type of correlation to calculate, may be ‘Pearson’, or ‘Spearman’
Returns:

Plotly figure

Return type:

nPYc.plotting.plotTargetedFeatureDistribution(datasetOriginal, featureName='Feature Name', featureMask=None, sampleTypes=['SS', 'SP', 'ER'], logx=False, figures=None, savePath=None, figureFormat='png', dpi=72, figureSize=(11, 7))

Plot the distribution (violin plots) of a set of features, e.g., peakPantheR outputs, coloured by sample type

Parameters:
  • dataset (MSDataset) – MSDataset
  • logx (bool) – If True log-scale the x-axis
  • figures (dict) – If not None, saves location of each figure for output in html report (see _generateMSReport.py)