nmraspecds.plotting module

plotting module of the nmraspecds package.

class nmraspecds.plotting.PlotterExtensions

Bases: object

Extensions for plots of NMR data.

This class is meant as a mixin class for plotters of the nmraspecds package and provides functionality specific for NMR-spectroscopic data.

Hence it can only be used as mixin in addition to a plotter class.

parameters

All parameters necessary for the plot, implicit and explicit

The following keys exist, in addition to those defined by the actual plotter:

frequency-axis: bool

Whether to show an additional frquency axis opposite of the chemical shift axis

This assumes the chemical shift axis to be the x axis and then calculates the offset frequency from the frequency of the nucleus.

Type:

dict

Important

If you add a frequency axis to your plot, and at the same time specify a figure title, this will result in the figure title clashing with the frequency axis. The solution: set an axes title rather than a figure title.

class nmraspecds.plotting.SinglePlotter1D

Bases: SinglePlotter1D, PlotterExtensions

1D plots of single datasets.

Convenience class taking care of 1D plots of single datasets.

As the class is fully inherited from ASpecD for simple usage, see the ASpecD documentation of the aspecd.plotting.SinglePlotter1D class for details.

Furthermore, the class inhertis all functionality from PlotterExtensions. See there for additional details.

Examples

For convenience, a series of examples in recipe style (for details of the recipe-driven data analysis, see aspecd.tasks) is given below for how to make use of this class. Of course, all parameters settable for the superclasses can be set as well. The examples focus each on a single aspect.

In the simplest case, just invoke the plotter with default values:

- kind: singleplot
  type: SinglePlotter1D
  properties:
    filename: output.pdf

In case you would like to have a frequency axis plotted as a second x axis on top:

- kind: singleplot
  type: SinglePlotter1D
  properties:
    parameters:
      frequency-axis: true
    filename: output.pdf

Important

If you add a frequency axis to your plot, and at the same time specify a figure title, this will result in the figure title clashing with the frequency axis. The solution: set an axes title rather than a figure title.

property allowed_types

Return the allowed plot types.

Currently, the allowed types are: plot, scatter, step, loglog, semilogx, semilogy, stemplot.

Returns:

allowed_types – List of strings

Return type:

list

annotate(annotation=None)

Add annotation to dataset.

Parameters:

annotation (aspecd.annotation.PlotAnnotation) – Annotation to add to the plotter

Returns:

annotation – Annotation added to the plot(ter)

Return type:

aspecd.annotation.PlotAnnotation

static applicable(data)

Check whether plot is applicable to the dataset.

Checks for the dimension of the data of the dataset, i.e. the aspecd.dataset.Data.data attribute. Returns True if data are one-dimensional, and False otherwise.

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

property ax

Short hand for axes.

create_history_record()

Create history record to be added to the dataset.

Usually, this method gets called from within the aspecd.dataset.Dataset.plot() method of the aspecd.dataset.Dataset class and ensures the history of each plotting step to get written properly.

Returns:

history_record – history record for plotting step

Return type:

aspecd.history.PlotHistoryRecord

delete_annotation(index=None)

Remove annotation record from dataset.

Parameters:

index (int) – Number of analysis in analyses to delete

property fig

Shorthand for figure.

plot(dataset=None, from_dataset=False)

Perform the actual plotting on the given dataset.

If no dataset is set as property in the object, the method will raise a respective exception. The Dataset object plot() method always assigns its dataset as the respective dataset attribute of the plotter class.

The actual plotting should be implemented within the non-public method _create_plot(). Besides that, the applicability of the plotting to the given dataset will be checked automatically. These checks should be implemented in the method applicable().

Note that the axis labels are added automatically. If you ever need to change the handling or appearance of your axis labels, you may want to override the corresponding methods _set_axes_labels() and _create_axis_label_string(), respectively.

Parameters:
  • dataset (aspecd.dataset.Dataset) – dataset to perform plot for

  • from_dataset (boolean) –

    whether we are called from within a dataset

    Defaults to “False” and shall never be set manually.

Returns:

dataset – dataset plot has been performed for

Return type:

aspecd.dataset.Dataset

Raises:
save(saver=None)

Save the plot to a file.

The actual saving is postponed to an object of class aspecd.plotting.Saver that is submitted as parameter.

Parameters:

saver (aspecd.plotting.Saver) – Saver handling the actual saving of the plot

Returns:

saver – Saver used to save the plot

Return type:

aspecd.plotting.Saver

Raises:

aspecd.exceptions.MissingSaverError – Raised if no Saver is provided as parameter.

to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict

Changed in version 0.6: New parameter remove_empty

Changed in version 0.9: Settings for properties to exclude and include are not traversed

Changed in version 0.9.1: Dictionaries get copied before traversing, as otherwise, the special variables __dict__ and __0dict__ are modified, what may result in strange behaviour.

Changed in version 0.9.2: Dictionaries do not get copied by default, but there is a private method that can be overridden in derived classes to copy the dictionary.

property type

Get or set the plot type.

Types need to be methods of the matplotlib.axes.Axes class.

Allowed plot types are stored in the aspecd.plotting.SinglePlotter1D.allowed_types attribute.

Default: ‘plot’

Raises:

TypeError – Raised in case of wrong type

class nmraspecds.plotting.SinglePlotter2D

Bases: SinglePlotter2D, PlotterExtensions

2D plots of single datasets.

Convenience class taking care of 2D plots of single datasets.

As the class is fully inherited from ASpecD for simple usage, see the ASpecD documentation of the aspecd.plotting.SinglePlotter2D class for details.

Furthermore, the class inherits all functionality from PlotterExtensions. See there for additional details.

Examples

For convenience, a series of examples in recipe style (for details of the recipe-driven data analysis, see aspecd.tasks) is given below for how to make use of this class. Of course, all parameters settable for the superclasses can be set as well. The examples focus each on a single aspect.

In the simplest case, just invoke the plotter with default values:

- kind: singleplot
  type: SinglePlotter2D
  properties:
    filename: output.pdf

To change the axes (flip x and y axis):

- kind: singleplot
  type: SinglePlotter2D
  properties:
    filename: output.pdf
    parameters:
      switch_axes: True

To use another type (here: contour):

- kind: singleplot
  type: SinglePlotter2D
  properties:
    filename: output.pdf
    type: contour

To set the number of levels of a contour plot to 10:

- kind: singleplot
  type: SinglePlotter2D
  properties:
    filename: output.pdf
    type: contour
    parameters:
      levels: 10

To change the colormap (cmap) used:

- kind: singleplot
  type: SinglePlotter2D
  properties:
    filename: output.pdf
    properties:
      drawing:
        cmap: RdGy

Make sure to check the documentation of the ASpecD aspecd.plotting module for further parameters that can be set.

In case you would like to have a frequency axis plotted as a second x axis on top:

- kind: singleplot
  type: SinglePlotter2D
  properties:
    parameters:
      frequency-axis: true
    filename: output.pdf

Important

If you add a frequency axis to your plot, and at the same time specify a figure title, this will result in the figure title clashing with the frequency axis. The solution: set an axes title rather than a figure title.

property allowed_types

Return the allowed plot types.

Currently allowed types are: contour, contourf, imshow

Returns:

allowed_types – List of strings

Return type:

list

annotate(annotation=None)

Add annotation to dataset.

Parameters:

annotation (aspecd.annotation.PlotAnnotation) – Annotation to add to the plotter

Returns:

annotation – Annotation added to the plot(ter)

Return type:

aspecd.annotation.PlotAnnotation

static applicable(data)

Check whether plot is applicable to the given dataset.

Checks for the dimension of the data of the dataset, i.e. the aspecd.dataset.Data.data attribute. Returns True if data are two-dimensional, and False otherwise.

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

property ax

Short hand for axes.

create_history_record()

Create history record to be added to the dataset.

Usually, this method gets called from within the aspecd.dataset.Dataset.plot() method of the aspecd.dataset.Dataset class and ensures the history of each plotting step to get written properly.

Returns:

history_record – history record for plotting step

Return type:

aspecd.history.PlotHistoryRecord

delete_annotation(index=None)

Remove annotation record from dataset.

Parameters:

index (int) – Number of analysis in analyses to delete

property fig

Shorthand for figure.

plot(dataset=None, from_dataset=False)

Perform the actual plotting on the given dataset.

If no dataset is set as property in the object, the method will raise a respective exception. The Dataset object plot() method always assigns its dataset as the respective dataset attribute of the plotter class.

The actual plotting should be implemented within the non-public method _create_plot(). Besides that, the applicability of the plotting to the given dataset will be checked automatically. These checks should be implemented in the method applicable().

Note that the axis labels are added automatically. If you ever need to change the handling or appearance of your axis labels, you may want to override the corresponding methods _set_axes_labels() and _create_axis_label_string(), respectively.

Parameters:
  • dataset (aspecd.dataset.Dataset) – dataset to perform plot for

  • from_dataset (boolean) –

    whether we are called from within a dataset

    Defaults to “False” and shall never be set manually.

Returns:

dataset – dataset plot has been performed for

Return type:

aspecd.dataset.Dataset

Raises:
save(saver=None)

Save the plot to a file.

The actual saving is postponed to an object of class aspecd.plotting.Saver that is submitted as parameter.

Parameters:

saver (aspecd.plotting.Saver) – Saver handling the actual saving of the plot

Returns:

saver – Saver used to save the plot

Return type:

aspecd.plotting.Saver

Raises:

aspecd.exceptions.MissingSaverError – Raised if no Saver is provided as parameter.

to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict

Changed in version 0.6: New parameter remove_empty

Changed in version 0.9: Settings for properties to exclude and include are not traversed

Changed in version 0.9.1: Dictionaries get copied before traversing, as otherwise, the special variables __dict__ and __0dict__ are modified, what may result in strange behaviour.

Changed in version 0.9.2: Dictionaries do not get copied by default, but there is a private method that can be overridden in derived classes to copy the dictionary.

property type

Get or set the plot type.

Types need to be methods of the matplotlib.axes.Axes class.

Allowed plot types are stored in the aspecd.plotting.SinglePlotter2D.allowed_types attribute.

Default: ‘imshow’

Raises:

TypeError – Raised in case of wrong type

class nmraspecds.plotting.SinglePlotter2DStacked

Bases: SinglePlotter2DStacked, PlotterExtensions

Stacked plots of 2D data.

A stackplot creates a series of lines stacked on top of each other from a 2D dataset.

As the class is fully inherited from ASpecD for simple usage, see the ASpecD documentation of the aspecd.plotting.SinglePlotter2DStacked class for details.

Furthermore, the class inherits all functionality from PlotterExtensions. See there for additional details.

Examples

For convenience, a series of examples in recipe style (for details of the recipe-driven data analysis, see aspecd.tasks) is given below for how to make use of this class. Of course, all parameters settable for the superclasses can be set as well. The examples focus each on a single aspect.

In the simplest case, just invoke the plotter with default values:

- kind: singleplot
  type: SinglePlotter2DStacked
  properties:
    filename: output.pdf

If you need to more precisely control the formatting of the y tick labels, particularly the number of decimals shown, you can set the formatting accordingly:

- kind: singleplot
  type: SinglePlotter2DStacked
  properties:
    filename: output.pdf
    parameters:
      yticklabelformat: '%.2f'

In this particular case, the y tick labels will appear with only two decimals. Note that currently, the “old style” formatting specifications are used due to their widespread use in other programming languages and hence the familiarity of many users with this particular notation.

Sometimes you want to have horizontal “zero lines” appear for each individual trace of the stacked plot. This can be achieved explicitly setting the “show_zero_lines” parameter to “True” that is set to “False” by default:

- kind: singleplot
  type: SinglePlotter2DStacked
  properties:
    filename: output.pdf
    parameters:
      show_zero_lines: True

In case you would like to have a frequency axis plotted as a second x axis on top:

- kind: singleplot
  type: SinglePlotter2DStacked
  properties:
    parameters:
      frequency-axis: true
    filename: output.pdf

Important

If you add a frequency axis to your plot, and at the same time specify a figure title, this will result in the figure title clashing with the frequency axis. The solution: set an axes title rather than a figure title.

annotate(annotation=None)

Add annotation to dataset.

Parameters:

annotation (aspecd.annotation.PlotAnnotation) – Annotation to add to the plotter

Returns:

annotation – Annotation added to the plot(ter)

Return type:

aspecd.annotation.PlotAnnotation

static applicable(data)

Check whether plot is applicable to the dataset.

Checks for the dimension of the data of the dataset, i.e. the aspecd.dataset.Data.data attribute. Returns True if data are two-dimensional, and False otherwise.

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

property ax

Short hand for axes.

create_history_record()

Create history record to be added to the dataset.

Usually, this method gets called from within the aspecd.dataset.Dataset.plot() method of the aspecd.dataset.Dataset class and ensures the history of each plotting step to get written properly.

Returns:

history_record – history record for plotting step

Return type:

aspecd.history.PlotHistoryRecord

delete_annotation(index=None)

Remove annotation record from dataset.

Parameters:

index (int) – Number of analysis in analyses to delete

property drawings

Actual graphical representation of the data.

List of matplotlib.artist.Artist objects, one for each of the actual lines of the plot

This is identical to drawing and has been added to work conveniently with SinglePlot2DStackedProperties.

Returns:

drawings – Actual graphical representation of the data.

Return type:

list

Added in version 0.10.

property fig

Shorthand for figure.

plot(dataset=None, from_dataset=False)

Perform the actual plotting on the given dataset.

If no dataset is set as property in the object, the method will raise a respective exception. The Dataset object plot() method always assigns its dataset as the respective dataset attribute of the plotter class.

The actual plotting should be implemented within the non-public method _create_plot(). Besides that, the applicability of the plotting to the given dataset will be checked automatically. These checks should be implemented in the method applicable().

Note that the axis labels are added automatically. If you ever need to change the handling or appearance of your axis labels, you may want to override the corresponding methods _set_axes_labels() and _create_axis_label_string(), respectively.

Parameters:
  • dataset (aspecd.dataset.Dataset) – dataset to perform plot for

  • from_dataset (boolean) –

    whether we are called from within a dataset

    Defaults to “False” and shall never be set manually.

Returns:

dataset – dataset plot has been performed for

Return type:

aspecd.dataset.Dataset

Raises:
save(saver=None)

Save the plot to a file.

The actual saving is postponed to an object of class aspecd.plotting.Saver that is submitted as parameter.

Parameters:

saver (aspecd.plotting.Saver) – Saver handling the actual saving of the plot

Returns:

saver – Saver used to save the plot

Return type:

aspecd.plotting.Saver

Raises:

aspecd.exceptions.MissingSaverError – Raised if no Saver is provided as parameter.

to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict

Changed in version 0.6: New parameter remove_empty

Changed in version 0.9: Settings for properties to exclude and include are not traversed

Changed in version 0.9.1: Dictionaries get copied before traversing, as otherwise, the special variables __dict__ and __0dict__ are modified, what may result in strange behaviour.

Changed in version 0.9.2: Dictionaries do not get copied by default, but there is a private method that can be overridden in derived classes to copy the dictionary.

class nmraspecds.plotting.MultiPlotter1D

Bases: MultiPlotter1D, PlotterExtensions

1D plots of multiple datasets.

Convenience class taking care of 1D plots of multiple datasets.

As the class is fully inherited from ASpecD for simple usage, see the ASpecD documentation of the aspecd.plotting.MultiPlotter1D class for details.

Furthermore, the class inherits all functionality from PlotterExtensions. See there for additional details.

Examples

For convenience, a series of examples in recipe style (for details of the recipe-driven data analysis, see aspecd.tasks) is given below for how to make use of this class. Of course, all parameters settable for the superclasses can be set as well. The examples focus each on a single aspect.

In the simplest case, just invoke the plotter with default values:

- kind: multiplot
  type: MultiPlotter1D
  properties:
    filename: output.pdf

To change the settings of each individual line (here the colour and label), supposing you have three lines, you need to specify the properties in a list for each of the drawings:

- kind: multiplot
  type: MultiPlotter1D
  properties:
    filename: output.pdf
    properties:
      drawings:
        - color: '#FF0000'
          label: foo
        - color: '#00FF00'
          label: bar
        - color: '#0000FF'
          label: foobar

Important

If you set colours using the hexadecimal RGB triple prefixed by #, you need to explicitly tell YAML that these are strings, surrounding the values by quotation marks.

In case you would like to have a frequency axis plotted as a second x axis on top:

- kind: multiplot
  type: MultiPlotter1D
  properties:
    parameters:
      frequency-axis: true
    filename: output.pdf

Important

If you add a frequency axis to your plot, and at the same time specify a figure title, this will result in the figure title clashing with the frequency axis. The solution: set an axes title rather than a figure title.

property allowed_types

Return the allowed plot types.

Currently, the allowed types are: plot, step, loglog, semilogx, semilogy.

Returns:

allowed_types – List of strings

Return type:

list

annotate(annotation=None)

Add annotation to dataset.

Parameters:

annotation (aspecd.annotation.PlotAnnotation) – Annotation to add to the plotter

Returns:

annotation – Annotation added to the plot(ter)

Return type:

aspecd.annotation.PlotAnnotation

static applicable(data)

Check whether plot is applicable to the given dataset.

Checks for the dimension of the data of the dataset, i.e. the aspecd.dataset.Data.data attribute. Returns True if data are one-dimensional, and False otherwise.

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

property ax

Short hand for axes.

delete_annotation(index=None)

Remove annotation record from dataset.

Parameters:

index (int) – Number of analysis in analyses to delete

property fig

Shorthand for figure.

plot()

Perform the actual plotting on the given list of datasets.

If no dataset is added to the list of datasets of the object, the method will raise a respective exception.

The actual plotting should be implemented within the non-public method _create_plot(). Besides that, the applicability of the plotting to the given list of datasets will be checked automatically. These checks should be implemented in the method applicable().

Note

There is two ways of setting axes labels: The user may provide the information required in the “axes” key of the aspecd.plotting.Plotter.parameters property containing a list of aspecd.dataset.Axis objects. Alternatively, if no such information is provided, the axes of each dataset are checked for consistency, and if they are found to be identical, this information is used.

Raises:
save(saver=None)

Save the plot to a file.

The actual saving is postponed to an object of class aspecd.plotting.Saver that is submitted as parameter.

Parameters:

saver (aspecd.plotting.Saver) – Saver handling the actual saving of the plot

Returns:

saver – Saver used to save the plot

Return type:

aspecd.plotting.Saver

Raises:

aspecd.exceptions.MissingSaverError – Raised if no Saver is provided as parameter.

to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict

Changed in version 0.6: New parameter remove_empty

Changed in version 0.9: Settings for properties to exclude and include are not traversed

Changed in version 0.9.1: Dictionaries get copied before traversing, as otherwise, the special variables __dict__ and __0dict__ are modified, what may result in strange behaviour.

Changed in version 0.9.2: Dictionaries do not get copied by default, but there is a private method that can be overridden in derived classes to copy the dictionary.

property type

Get or set the plot type.

Types need to be methods of the matplotlib.axes.Axes class.

Allowed plot types are stored in the aspecd.plotting.SinglePlotter1D.allowed_types attribute.

Default: ‘plot’

Raises:

TypeError – Raised in case of wrong type

class nmraspecds.plotting.MultiPlotter1DStacked

Bases: MultiPlotter1DStacked, PlotterExtensions

Stacked 1D plots of multiple datasets.

Convenience class taking care of 1D plots of multiple datasets.

As the class is fully inherited from ASpecD for simple usage, see the ASpecD documentation of the aspecd.plotting.MultiPlotter1DStacked class for details.

Furthermore, the class inherits all functionality from PlotterExtensions. See there for additional details.

Examples

For convenience, a series of examples in recipe style (for details of the recipe-driven data analysis, see aspecd.tasks) is given below for how to make use of this class. Of course, all parameters settable for the superclasses can be set as well. The examples focus each on a single aspect.

In the simplest case, just invoke the plotter with default values:

- kind: multiplot
  type: MultiPlotter1DStacked
  properties:
    filename: output.pdf

To change the settings of each individual line (here the colour and label), supposing you have three lines, you need to specify the properties in a list for each of the drawings:

- kind: multiplot
  type: MultiPlotter1DStacked
  properties:
    filename: output.pdf
    properties:
      drawings:
        - color: '#FF0000'
          label: foo
        - color: '#00FF00'
          label: bar
        - color: '#0000FF'
          label: foobar

Important

If you set colours using the hexadecimal RGB triple prefixed by #, you need to explicitly tell YAML that these are strings, surrounding the values by quotation marks.

Sometimes you want to have horizontal “zero lines” appear for each individual trace of the stacked plot. This can be achieved explicitly setting the “show_zero_lines” parameter to “True” that is set to “False” by default:

- kind: multiplot
  type: MultiPlotter1DStacked
  properties:
    filename: output.pdf
    parameters:
      show_zero_lines: True

In case you would like to have a frequency axis plotted as a second x axis on top:

- kind: multiplot
  type: MultiPlotter1DStacked
  properties:
    parameters:
      frequency-axis: true
    filename: output.pdf

Important

If you add a frequency axis to your plot, and at the same time specify a figure title, this will result in the figure title clashing with the frequency axis. The solution: set an axes title rather than a figure title.

property allowed_types

Return the allowed plot types.

Currently, the allowed types are: plot, step, loglog, semilogx, semilogy.

Returns:

allowed_types – List of strings

Return type:

list

annotate(annotation=None)

Add annotation to dataset.

Parameters:

annotation (aspecd.annotation.PlotAnnotation) – Annotation to add to the plotter

Returns:

annotation – Annotation added to the plot(ter)

Return type:

aspecd.annotation.PlotAnnotation

static applicable(data)

Check whether plot is applicable to the given dataset.

Checks for the dimension of the data of the dataset, i.e. the aspecd.dataset.Data.data attribute. Returns True if data are one-dimensional, and False otherwise.

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

property ax

Short hand for axes.

delete_annotation(index=None)

Remove annotation record from dataset.

Parameters:

index (int) – Number of analysis in analyses to delete

property fig

Shorthand for figure.

plot()

Perform the actual plotting on the given list of datasets.

If no dataset is added to the list of datasets of the object, the method will raise a respective exception.

The actual plotting should be implemented within the non-public method _create_plot(). Besides that, the applicability of the plotting to the given list of datasets will be checked automatically. These checks should be implemented in the method applicable().

Note

There is two ways of setting axes labels: The user may provide the information required in the “axes” key of the aspecd.plotting.Plotter.parameters property containing a list of aspecd.dataset.Axis objects. Alternatively, if no such information is provided, the axes of each dataset are checked for consistency, and if they are found to be identical, this information is used.

Raises:
save(saver=None)

Save the plot to a file.

The actual saving is postponed to an object of class aspecd.plotting.Saver that is submitted as parameter.

Parameters:

saver (aspecd.plotting.Saver) – Saver handling the actual saving of the plot

Returns:

saver – Saver used to save the plot

Return type:

aspecd.plotting.Saver

Raises:

aspecd.exceptions.MissingSaverError – Raised if no Saver is provided as parameter.

to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict

Changed in version 0.6: New parameter remove_empty

Changed in version 0.9: Settings for properties to exclude and include are not traversed

Changed in version 0.9.1: Dictionaries get copied before traversing, as otherwise, the special variables __dict__ and __0dict__ are modified, what may result in strange behaviour.

Changed in version 0.9.2: Dictionaries do not get copied by default, but there is a private method that can be overridden in derived classes to copy the dictionary.

property type

Get or set the plot type.

Types need to be methods of the matplotlib.axes.Axes class.

Allowed plot types are stored in the aspecd.plotting.SinglePlotter1D.allowed_types attribute.

Default: ‘plot’

Raises:

TypeError – Raised in case of wrong type

class nmraspecds.plotting.FittingPlotter2D

Bases: SinglePlotter2DStacked

Plotter for fitted data with a special color scheme.

Creates a special type of plot with the experimental data (black), the sum of the single, fitted peaks (red) and all single peaks (grey). Experimental data were previously fitted with DMFit, exported ( experimental dataset with sum and all peaks) are imported with nmraspecds.io.FittingImporter. See the importer for details to the dataset.

Providing a colormap changes the default colors of the plot.

attr

Short description

Type:

None

Raises:

exception – Short description when and why raised

Examples

The easiest way to use this Plotter

- kind: singleplot
  type: FittingPlotter2D
  properties:
    filename: output.pdf
put_maxima_below_curves()
get_maxima()
annotate(annotation=None)

Add annotation to dataset.

Parameters:

annotation (aspecd.annotation.PlotAnnotation) – Annotation to add to the plotter

Returns:

annotation – Annotation added to the plot(ter)

Return type:

aspecd.annotation.PlotAnnotation

static applicable(data)

Check whether plot is applicable to the dataset.

Checks for the dimension of the data of the dataset, i.e. the aspecd.dataset.Data.data attribute. Returns True if data are two-dimensional, and False otherwise.

Returns:

applicableTrue if successful, False otherwise.

Return type:

bool

property ax

Short hand for axes.

create_history_record()

Create history record to be added to the dataset.

Usually, this method gets called from within the aspecd.dataset.Dataset.plot() method of the aspecd.dataset.Dataset class and ensures the history of each plotting step to get written properly.

Returns:

history_record – history record for plotting step

Return type:

aspecd.history.PlotHistoryRecord

delete_annotation(index=None)

Remove annotation record from dataset.

Parameters:

index (int) – Number of analysis in analyses to delete

property drawings

Actual graphical representation of the data.

List of matplotlib.artist.Artist objects, one for each of the actual lines of the plot

This is identical to drawing and has been added to work conveniently with SinglePlot2DStackedProperties.

Returns:

drawings – Actual graphical representation of the data.

Return type:

list

Added in version 0.10.

property fig

Shorthand for figure.

plot(dataset=None, from_dataset=False)

Perform the actual plotting on the given dataset.

If no dataset is set as property in the object, the method will raise a respective exception. The Dataset object plot() method always assigns its dataset as the respective dataset attribute of the plotter class.

The actual plotting should be implemented within the non-public method _create_plot(). Besides that, the applicability of the plotting to the given dataset will be checked automatically. These checks should be implemented in the method applicable().

Note that the axis labels are added automatically. If you ever need to change the handling or appearance of your axis labels, you may want to override the corresponding methods _set_axes_labels() and _create_axis_label_string(), respectively.

Parameters:
  • dataset (aspecd.dataset.Dataset) – dataset to perform plot for

  • from_dataset (boolean) –

    whether we are called from within a dataset

    Defaults to “False” and shall never be set manually.

Returns:

dataset – dataset plot has been performed for

Return type:

aspecd.dataset.Dataset

Raises:
save(saver=None)

Save the plot to a file.

The actual saving is postponed to an object of class aspecd.plotting.Saver that is submitted as parameter.

Parameters:

saver (aspecd.plotting.Saver) – Saver handling the actual saving of the plot

Returns:

saver – Saver used to save the plot

Return type:

aspecd.plotting.Saver

Raises:

aspecd.exceptions.MissingSaverError – Raised if no Saver is provided as parameter.

to_dict(remove_empty=False)

Create dictionary containing public attributes of an object.

Parameters:

remove_empty (bool) –

Whether to remove keys with empty values

Default: False

Returns:

public_attributes – Ordered dictionary containing the public attributes of the object

The order of attribute definition is preserved

Return type:

collections.OrderedDict

Changed in version 0.6: New parameter remove_empty

Changed in version 0.9: Settings for properties to exclude and include are not traversed

Changed in version 0.9.1: Dictionaries get copied before traversing, as otherwise, the special variables __dict__ and __0dict__ are modified, what may result in strange behaviour.

Changed in version 0.9.2: Dictionaries do not get copied by default, but there is a private method that can be overridden in derived classes to copy the dictionary.