Plotters: visualizing ixdat data

Sourece: https://github.com/ixdat/ixdat/tree/user_ready/src/ixdat/plotters

Basic

The base_mpl_plotter module

The value_plotter module

Classes for plotting measurement data

class ixdat.plotters.value_plotter.ValuePlotter(measurement=None)[source]

Default plotter. By default plots all of the VSeries vs time on a single axis

plot(*args, **kwargs)[source]

Plot the exporter’s measurement via plotter.plot_measurement()

plot_measurement(measurement=None, v_list=None, tspan=None, ax=None, legend=True, logscale=False)[source]

Plot a measurement’s values vs time

Parameters:
  • measurement (Measurement) – The measurement to plot
  • v_list (list of str) – The names of the data series to include. Defaults to names of all VSeries in the measurement.
  • tspan (timespan) – The timespan to include in the file, defaults to all of it
  • legend (bool) – Whether to include a legend. Defaults to True.
  • logscale (bool) – Whether to use a log-scaled y-axis. Defaults to False.

Electrochemistry

The ec_plotter module

class ixdat.plotters.ec_plotter.CVDiffPlotter(measurement=None)[source]

A matplotlib plotter for highlighting the difference between two cv’s.

plot_vs_potential()[source]

FIXME: This is needed to satisfy ECMeasurement.__init__

class ixdat.plotters.ec_plotter.ECPlotter(measurement=None)[source]

A matplotlib plotter specialized in electrochemistry measurements.

plot_measurement(*, measurement=None, tspan=None, V_str=None, J_str=None, axes=None, V_color='k', J_color='r', **kwargs)[source]

Plot two variables on two y-axes vs time

All arguments are optional. By default it plots potential in black on the left y-axis and current in red on the right y-axis, using data from its entire measurement. The axes are colored to match the traces and labled witht the respective series names.

Parameters:
  • measurement (Measurement) – The measurement to plot, if not the one the plotter was initiated with.
  • tspan (iter of float) – The timespan (wrt to measurement.tstamp) to plot.
  • V_str (string) – The name of the ValueSeries to plot on the left y-axis. Defaults to measurement.V_str, which for an ECMeasurement is the name of its most calibrated/correct potential.
  • J_str (string) – The name of the ValueSeries to plot on the right y-axis. Defaults to measurement.J_str, which for an ECMeasurement is the name of its most normalized/correct current.
  • axes (list of matplotlib.Axis) – Two axes to plot on, if not the default new twinx()’d axes. axes[0] is for V_str and axes[1] for J_str.
  • V_color (str) – The color to plot the series called V_str. Defaults to black.
  • J_color (str) – The color to plot the series called J_str. Defaults to red.
  • kwargs (dict) – Additional key-word arguments are passed to matplotlib’s plot() function, for both potential and current.

Returns list of matplotlib.pyplot.Axis: The axes plotted on.

plot_vs_potential(measurement=None, tspan=None, V_str=None, J_str=None, ax=None, **kwargs)[source]

Plot an ECMeasurement with electrode potential on the x-axis.

This can actually plot with anything on the x-axis, by specifying what you want on the x-axis using V_str. The y-axis variable, which can be specified by J_str, is interpolated onto the time corresponding to the x-axis variable. TODO: This is a special case of the not-yet-implemented generalized TODO: plot_vs. Consider an inheritance structure to reduce redundancy in TODO: future plotters. All arguments are optional. By default it will plot current vs potential in black on a single axis for the whole experiment. TODO: color gradient (cmap=inferno) from first to last cycle.

Parameters:
  • measurement (Measurement) – What to plot. Defaults to the measurement the plotter was initialized with
  • tspan (iter of float) – The timespan, relative to vs measurement.tstamp, on which to plot.
  • V_str (str) – Name of the x-axis ValueSeries. Defaults to calibrated potential
  • J_str (str) – Name of the y-axis ValueSeries. Defaults to normalized current.
  • ax (matplotlib.pyplot.Axis) – The axis to plot on, if not a new one.
  • kwargs – Additional key-word arguments are passed to matplotlib’s plot() function, including color.

Returns matplotlib.pyplot.axis: The axis plotted on.

Mass Spectrometry

The ms_plotter module

class ixdat.plotters.ms_plotter.MSPlotter(measurement=None)[source]

A matplotlib plotter specialized in mass spectrometry MID measurements.

plot_measurement(*, measurement=None, ax=None, axes=None, mass_list=None, mass_lists=None, mol_list=None, mol_lists=None, tspan=None, tspan_bg=None, removebackground=None, unit=None, logplot=True, legend=True, **kwargs)[source]

Plot m/z signal vs time (MID) data and return the axis.

There are four ways to specify what to plot. Only specify one of these::
mass_list: Uncalibrated signals in [(u/n/p)A] on on axis mass_lists: Uncalibrated signals in [(u/n/p)A] on two axes mol_list: Calibrated signals in [(u/n/p)mol/s] on on axis mol_lists: Calibrated signals in [(u/n/p)mol/s] on two axes

Two axes refers to separate left and right y-axes. Default is to use all available masses as mass_list.

Parameters:
  • measurement (MSMeasurement) – defaults to the one that initiated the plotter
  • ax (matplotlib axis) – Defaults to a new axis
  • axes (list of matplotlib axis) – Left and right y-axes if mass_lists are given
  • mass_list (list of str) – The names of the m/z values, eg. [“M2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mass_lists (list of list of str) – Alternately, two lists can be given for masses in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • mol_list (list of str) – The names of the molecules, eg. [“H2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mol_lists (list of list of str) – Alternately, two lists can be given for molecules in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • tspan (iter of float) – The time interval to plot, wrt measurement.tstamp
  • tspan_bg (timespan) – A timespan for which to assume the signal is at its background. The average signals during this timespan are subtracted. If mass_lists are given rather than a single mass_list, tspan_bg must also be two timespans - one for each axis. Default is None for no background subtraction.
  • removebackground (bool) – Whether otherwise to subtract pre-determined background signals if available. Defaults to (not logplot)
  • unit (str) – defaults to “A” or “mol/s”
  • logplot (bool) – Whether to plot the MS data on a log scale (default True)
  • legend (bool) – Whether to use a legend for the MS data (default True)
  • kwargs – extra key-word args are passed on to matplotlib’s plot()
plot_vs(*, x_name, measurement=None, ax=None, axes=None, mass_list=None, mass_lists=None, mol_list=None, mol_lists=None, tspan=None, tspan_bg=None, removebackground=None, unit=None, logplot=True, legend=True, **kwargs)[source]

Plot m/z signal (MID) data against a specified variable and return the axis.

There are four ways to specify what to plot. Only specify one of these::
mass_list: Uncalibrated signals in [(u/n/p)A] on on axis mass_lists: Uncalibrated signals in [(u/n/p)A] on two axes mol_list: Calibrated signals in [(u/n/p)mol/s] on on axis mol_lists: Calibrated signals in [(u/n/p)mol/s] on two axes

Two axes refers to seperate left and right y-axes. Default is to use all available masses as mass_list.

Parameters:
  • x_name (str) – Name of the variable to plot on the x-axis
  • measurement (MSMeasurement) – defaults to the one that initiated the plotter
  • ax (matplotlib axis) – Defaults to a new axis
  • axes (list of matplotlib axis) – Left and right y-axes if mass_lists are given
  • mass_list (list of str) – The names of the m/z values, eg. [“M2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mass_lists (list of list of str) – Alternately, two lists can be given for masses in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • mol_list (list of str) – The names of the molecules, eg. [“H2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mol_lists (list of list of str) – Alternately, two lists can be given for molecules in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • tspan (iter of float) – The time interval to plot, wrt measurement.tstamp
  • tspan_bg (timespan) – A timespan for which to assume the signal is at its background. The average signals during this timespan are subtracted. If mass_lists are given rather than a single mass_list, tspan_bg must also be two timespans - one for each axis. Default is None for no background subtraction.
  • removebackground (bool) – Whether otherwise to subtract pre-determined background signals if available
  • logplot (bool) – Whether to plot the MS data on a log scale (default True)
  • legend (bool) – Whether to use a legend for the MS data (default True)
  • kwargs – key-word args are passed on to matplotlib’s plot()

EC-MS

The ecms_plotter module

class ixdat.plotters.ecms_plotter.ECMSPlotter(measurement=None)[source]

A matplotlib plotter for EC-MS measurements.

plot_measurement(*, measurement=None, axes=None, mass_list=None, mass_lists=None, mol_list=None, mol_lists=None, tspan=None, tspan_bg=None, removebackground=None, unit=None, V_str=None, J_str=None, V_color='k', J_color='r', logplot=None, legend=True, emphasis='top', **kwargs)[source]

Make an EC-MS plot vs time and return the axis handles.

Allocates tasks to ECPlotter.plot_measurement() and MSPlotter.plot_measurement()

TODO: add all functionality in the legendary plot_experiment() in EC_MS.Plotting
  • variable subplot sizing (emphasizing EC or MS)
  • plotting of calibrated data (mol_list instead of mass_list)
  • units!
Parameters:
  • measurement (ECMSMeasurement) – defaults to the measurement to which the plotter is bound (self.measurement)
  • axes (list of three matplotlib axes) – axes[0] plots the MID data, axes[1] the variable given by V_str (potential), and axes[2] the variable given by J_str (current). By default three axes are made with axes[0] a top panel with 3/5 the area, and axes[1] and axes[2] are the left and right y-axes of the lower panel with 2/5 the area.
  • mass_list (list of str) – The names of the m/z values, eg. [“M2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mass_lists (list of list of str) – Alternately, two lists can be given for masses in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • mol_list (list of str) – The names of the molecules, eg. [“H2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mol_lists (list of list of str) – Alternately, two lists can be given for molecules in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • tspan (iter of float) – The time interval to plot, wrt measurement.tstamp
  • tspan_bg (timespan) – A timespan for which to assume the signal is at its background. The average signals during this timespan are subtracted. If mass_lists are given rather than a single mass_list, tspan_bg must also be two timespans - one for each axis. Default is None for no background subtraction.
  • removebackground (bool) – Whether otherwise to subtract pre-determined background signals if available. Defaults to (not logplot)
  • unit (str) – the unit for the MS data. Defaults to “A” for Ampere
  • V_str (str) – The name of the value to plot on the lower left y-axis. Defaults to the name of the series measurement.potential
  • J_str (str) – The name of the value to plot on the lower right y-axis. Defaults to the name of the series measurement.current
  • V_color (str) – The color to plot the variable given by ‘V_str’
  • J_color (str) – The color to plot the variable given by ‘J_str’
  • logplot (bool) – Whether to plot the MS data on a log scale (default True unless mass_lists are given)
  • legend (bool) – Whether to use a legend for the MS data (default True)
  • emphasis (str or None) – “top” for bigger top panel, “bottom” for bigger bottom panel, None for equal-sized panels
  • kwargs (dict) – Additional kwargs go to all calls of matplotlib’s plot()
plot_vs_potential(*, measurement=None, axes=None, mass_list=None, mass_lists=None, mol_list=None, mol_lists=None, tspan=None, tspan_bg=None, removebackground=None, unit=None, logplot=False, legend=True, emphasis='top', **kwargs)[source]

“Make an EC-MS plot vs time and return the axis handles.

Allocates tasks to ECPlotter.plot_measurement() and MSPlotter.plot_measurement()

TODO: add all functionality in the legendary plot_experiment() in EC_MS.Plotting
  • variable subplot sizing (emphasizing EC or MS)
  • plotting of calibrated data (mol_list instead of mass_list)
  • units!
Parameters:
  • measurement (ECMSMeasurement) – defaults to the measurement to which the plotter is bound (self.measurement)
  • axes (list of three matplotlib axes) – axes[0] plots the MID data, axes[1] the current vs potential. By default three axes are made with axes[0] a top panel with 3/5 the area.
  • mass_list (list of str) – The names of the m/z values, eg. [“M2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mass_lists (list of list of str) – Alternately, two lists can be given for masses in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • mol_list (list of str) – The names of the molecules, eg. [“H2”, …] to plot. Defaults to all of them (measurement.mass_list)
  • mol_lists (list of list of str) – Alternately, two lists can be given for molecules in which case one list is plotted on the left y-axis and the other on the right y-axis of the top panel.
  • tspan (iter of float) – The time interval to plot, wrt measurement.tstamp
  • tspan_bg (timespan) – A timespan for which to assume the signal is at its background. The average signals during this timespan are subtracted. If mass_lists are given rather than a single mass_list, tspan_bg must also be two timespans - one for each axis. Default is None for no background subtraction.
  • removebackground (bool) – Whether otherwise to subtract pre-determined background signals if available. Defaults to (not logplot)
  • unit (str) – the unit for the MS data. Defaults to “A” for Ampere
  • logplot (bool) – Whether to plot the MS data on a log scale (default False)
  • legend (bool) – Whether to use a legend for the MS data (default True)
  • emphasis (str or None) – “top” for bigger top panel, “bottom” for bigger bottom panel, None for equal-sized panels
  • kwargs (dict) – Additional kwargs go to all calls of matplotlib’s plot()

Spectra

The spectrum_plotter module

class ixdat.plotters.spectrum_plotter.SpectrumPlotter(spectrum=None)[source]

A plotter for spectrums

plot(spectrum=None, ax=None, **kwargs)[source]

Plot a spectrum as y (signal) vs x (scanning variable)

Parameters:
  • spectrum (Spectrum) – The spectrum to plot if different from self.spectrum
  • ax (mpl.Axis) – The axis to plot on. A new one is made by default.
  • kwargs – additional key-word arguments are given to ax.plot()
class ixdat.plotters.spectrum_plotter.SpectrumSeriesPlotter(spectrum_series=None)[source]

A plotter for spectrum series, f.ex. spectra taken continuously over time

heat_plot(spectrum_series=None, field=None, tspan=None, xspan=None, ax=None, cmap_name='inferno', make_colorbar=False)[source]

Plot with time as x, the scanning variable as y, and color as signal

See SpectrumSeriesPlotter.heat_plot_vs(). This function calls it with vs=”t”.

heat_plot_vs(spectrum_series=None, field=None, vspan=None, xspan=None, ax=None, cmap_name='inferno', make_colorbar=False, vs=None)[source]

Plot an SECMeasurement in two panels with time as x-asis.

The top panel is a heat plot with wavelength on y-axis and color representing spectrum. At most one of V_ref and t_ref should be given, and if neither are given the measurement’s default reference_spectrum is used to calculate the optical density.

Parameters:
  • spectrum_series (SpectrumSeries) – The spectrum series to be plotted, if different from self.spectrum_series. FIXME: spectrum_series needs to actually be a Measurement to have other FIXME: series to plot against if vs isn’t in field.series_axes
  • field (Field) – The field to be plotted, if different from spectrum_series.field
  • xspan (iterable) – The span of the spectral data to plot
  • ax (mpl.Axis) – The axes to plot on. A new one is made by default
  • cmap_name (str) – The name of the colormap to use. Defaults to “inferno”, which ranges from black through red and orange to yellow-white. “jet” is also good.
  • make_colorbar (bool) – Whether to make a colorbar. FIXME: colorbar at present mis-alignes axes
  • vs (str) – The ValueSeries or TimeSeries to plot against.
plot

The default plot of a SpectrumSeries is heat_plot

plot_average(spectrum_series=None, ax=None, **kwargs)[source]

Take an average of the spectra and plot that.

plot_waterfall(spectrum_series=None, field=None, cmap_name='jet', make_colorbar=True, vs=None, ax=None)[source]

Plot a SpectrumSeries as spectra colored by the value at which they are taken

Parameters:
  • spectrum_series (SpectrumSeries) – The spectrum series to be plotted, if different from self.spectrum_series. FIXME: spectrum_series needs to actually be a Measurement to have other FIXME: …series to plot against if vs isn’t in field.series_axes
  • field (Field) – The field to be plotted, if different from spectrum_series.field
  • ax (matplotlib Axis) – The axes to plot on. A new one is made by default.
  • cmap_name (str) – The name of the colormap to use. Defaults to “inferno”, which ranges from black through red and orange to yellow-white. “jet” is also good.
  • make_colorbar (bool) – Whether to make a colorbar.
  • vs (str) – The name of the value to use for the color scale. Defaults to time

Spectroelectrochemistry

The sec_plotter module

class ixdat.plotters.sec_plotter.SECPlotter(measurement=None)[source]

An spectroelectrochemsitry (SEC) matplotlib plotter.

FIXME: This should make use of the code in spectrum_plotter.SpectrumSeriesPlotter

plot_measurement(measurement=None, tspan=None, wlspan=None, axes=None, V_ref=None, t_ref=None, cmap_name='inferno', make_colorbar=False, **kwargs)[source]

Plot an SECMeasurement in two panels with time as x-asis.

The top panel is a heat plot with wavelength on y-axis and color representing spectrum. At most one of V_ref and t_ref should be given, and if neither are given the measurement’s default reference_spectrum is used to calculate the optical density.

Parameters:
  • measurement (Measurement) – The measurement to be plotted, if different from self.measurement
  • tspan (timespan) – The timespan of data to keep for the measurement.
  • wlspan (iterable) – The wavelength span of spectral data to plot
  • axes (list of mpl.Axis) – The axes to plot on. axes[0] is for the heat plot, axes[1] for potential, and axes[2] for current. The axes are optional and a new set of axes, where axes[1] and axes[2] are twinned on x, are generated if not provided.
  • V_ref (float) – potential to use as reference for calculating optical density
  • t_ref (float) – time to use as a reference for calculating optical density
  • cmap_name (str) – The name of the colormap to use. Defaults to “inferno”, which ranges from black through red and orange to yellow-white. “jet” is also good.
  • make_colorbar (bool) – Whether to make a colorbar. FIXME: colorbar at present mis-alignes axes
  • kwargs – Additional key-word arguments are passed on to ECPlotter.plot_measurement().
plot_vs_potential(measurement=None, tspan=None, vspan=None, V_str=None, J_str=None, axes=None, wlspan=None, V_ref=None, cmap_name='inferno', make_colorbar=False, **kwargs)[source]

Plot an SECMeasurement in two panels with potential as x-asis.

The top panel is a heat plot with wavelength on y-axis and color representing spectrum. At most one of V_ref and t_ref should be given, and if neither are given the measurement’s default reference_spectrum is used to calculate the optical density.

Parameters:
  • measurement (Measurement) – The measurement to be plotted, if different from self.measurement
  • tspan (timespan) – The timespan of data to keep for the measurement.
  • vspan (timespan) – The potential span of data to keep for the measurement.
  • V_str (str) – Optional. The name of the data series to use as potential.
  • J_str (str) – Optional. The name of the data series to use as current.
  • wlspan (iterable) – The wavelength span of spectral data to plot
  • axes (list of numpy Axes) – The axes to plot on. axes[0] is for the heat plot and axes[1] for potential. New are made by default.
  • V_ref (float) – potential to use as reference for calculating optical density
  • t_ref (float) – time to use as a reference for calculating optical density
  • cmap_name (str) – The name of the colormap to use. Defaults to “inferno”, which ranges from black through red and orange to yellow-white. “jet” is also good.
  • make_colorbar (bool) – Whether to make a colorbar.
  • kwargs – Additional key-word arguments are passed on to ECPlotter.plot_vs_potential().
plot_waterfall(measurement=None, ax=None, V_ref=None, t_ref=None, cmap_name='jet', make_colorbar=True)[source]

Plot an SECMeasurement as spectra colored based on potential.

The top panel is a heat plot with wavelength on y-axis and color representing spectrum. At most one of V_ref and t_ref should be given, and if neither are given the measurement’s default reference_spectrum is used to calculate the optical density.

This uses SpectrumSeriesPlotter.plot_waterfall()

Parameters:
  • measurement (Measurement) – The measurement to be plotted, if different from self.measurement
  • tspan (timespan) – The timespan of data to keep for the measurement.
  • wlspan (iterable) – The wavelength span of spectral data to plot
  • ax (matplotlib Axis) – The axes to plot on. A new one is made by default.
  • V_ref (float) – potential to use as reference for calculating optical density
  • t_ref (float) – time to use as a reference for calculating optical density
  • cmap_name (str) – The name of the colormap to use. Defaults to “inferno”, which ranges from black through red and orange to yellow-white. “jet” is also good.
  • make_colorbar (bool) – Whether to make a colorbar.
plot_wavelengths(measurement=None, wavelengths=None, axes=None, cmap_name='jet', tspan=None, **kwargs)[source]

Plot the dO.D. for specific wavelength in the top panel and EC in bottom

Parameters:
  • measurement (Measurement) – The measurement to be plotted, if different from self.measurement
  • wavelengths (list of str) – The names of the wavelengths to track as strings, e.g. “w400” for 400 nm
  • axes (list of Ax) – The axes to plot on, defaults to new matplotlib axes
  • cmap_name (str) – Name of the colormap. Defaults to “jet”
  • tspan (timespan) – The timespan to plot
  • **kwargs – Additional key-word arguments are passed on to ECPlotter.plot_measurement
plot_wavelengths_vs_potential(measurement=None, wavelengths=None, axes=None, cmap_name='jet', tspan=None, **kwargs)[source]

Plot the dO.D. for specific wavelength in the top panel vs potential

Parameters:
  • measurement (Measurement) – The measurement to be plotted, if different from self.measurement
  • wavelengths (list of str) – The names of the wavelengths to track as strings, e.g. “w400” for 400 nm
  • axes (list of Ax) – The axes to plot on, defaults to new matplotlib axes
  • cmap_name (str) – Name of the colormap. Defaults to “jet”
  • tspan (timespan) – The timespan to plot
  • **kwargs – Additional key-word arguments are passed on to ECPlotter.plot_vs_potential