spinetoolbox.plotting

Functions for plotting on PlotWidget.

Currently plotting from the table views found in Graph, Tree and Tabular views are supported.

The main entrance points to plotting are: - plot_selection() which plots selected cells on a table view returning a PlotWidget object - plot_pivot_column() which is a specialized method for plotting entire columns of a pivot table - add_time_series_plot() which adds a time series plot to an existing PlotWidget - add_map_plot() which adds a map plot to an existing PlotWidget

author:
  1. Soininen(VTT)
date:

9.7.2019

Module Contents

exception spinetoolbox.plotting.PlottingError(message)[source]

Bases: Exception

An exception signalling failure in plotting.

Parameters:message (str) – an error message
message[source]

the error message.

Type:str
spinetoolbox.plotting.plot_pivot_column(proxy_model, column, hints, plot_widget=None)[source]

Returns a plot widget with a plot of an entire column in PivotTableModel.

Parameters:
  • proxy_model (PivotTableSortFilterProxy) – a pivot table filter
  • column (int) – a column index to the model
  • hints (PlottingHints) – a helper needed for e.g. plot labels
  • plot_widget (PlotWidget) – an existing plot widget to draw into or None to create a new widget
Returns:

a plot widget

Return type:

PlotWidget

spinetoolbox.plotting.plot_selection(model, indexes, hints, plot_widget=None)[source]

Returns a plot widget with plots of the selected indexes.

Parameters:
  • model (QAbstractTableModel) – a model
  • indexes (Iterable) – a list of QModelIndex objects for plotting
  • hints (PlottingHints) – a helper needed for e.g. plot labels
  • plot_widget (PlotWidget) – an existing plot widget to draw into or None to create a new widget
Returns:

a PlotWidget object

spinetoolbox.plotting.add_map_plot(plot_widget, map_value, label=None)[source]

Adds a map plot to a plot widget.

Parameters:
  • plot_widget (PlotWidget) – a plot widget to modify
  • map_value (Map) – the map to plot
  • label (str) – a label for the map
spinetoolbox.plotting.add_time_series_plot(plot_widget, value, label=None)[source]

Adds a time series step plot to a plot widget.

Parameters:
  • plot_widget (PlotWidget) – a plot widget to modify
  • value (TimeSeries) – the time series to plot
  • label (str) – a label for the time series
class spinetoolbox.plotting.PlottingHints[source]

A base class for plotting hints.

The functionality in this class allows the plotting functions to work without explicit knowledge of the underlying table model or widget.

cell_label(self, model, index)[source]

Returns a label for the cell given by index in a table.

column_label(self, model, column)[source]

Returns a label for a column.

filter_columns(self, selections, model)[source]

Filters columns and returns the filtered selections.

is_index_in_data(self, model, index)[source]

Returns true if the cell given by index is actually plottable data.

special_x_values(self, model, column, rows)[source]

Returns X values if available, otherwise returns None.

x_label(self, model)[source]

Returns a label for the x axis.

class spinetoolbox.plotting.ParameterTablePlottingHints[source]

Bases: spinetoolbox.plotting.PlottingHints

Support for plotting data in Parameter table views.

cell_label(self, model, index)[source]

Returns a label build from the columns on the left from the data column.

column_label(self, model, column)[source]

Returns the column header.

filter_columns(self, selections, model)[source]

Returns the ‘value’ or ‘default_value’ column only.

is_index_in_data(self, model, index)[source]

Always returns True.

special_x_values(self, model, column, rows)[source]

Always returns None.

x_label(self, model)[source]

Returns an empty string for the x axis label.

class spinetoolbox.plotting.PivotTablePlottingHints[source]

Bases: spinetoolbox.plotting.PlottingHints

Support for plotting data in Tabular view.

cell_label(self, model, index)[source]

Returns a label for the table cell given by index.

column_label(self, model, column)[source]

Returns a label for a table column.

filter_columns(self, selections, model)[source]

Filters the X column from selections.

is_index_in_data(self, model, index)[source]

Returns True if index is in the data portion of the table.

special_x_values(self, model, column, rows)[source]

Returns the values from the X column if one is designated otherwise returns None.

x_label(self, model)[source]

Returns the label of the X column, if available.

static _map_column_to_source(proxy_model, proxy_column)[source]

Maps a proxy model column to source model.

static _map_column_from_source(proxy_model, source_column)[source]

Maps a source model column to proxy model.

spinetoolbox.plotting._add_plot_to_widget(values, labels, plot_widget)[source]

Adds a new plot to plot_widget.

spinetoolbox.plotting._raise_if_types_inconsistent(values)[source]

Raises an exception if not all values are TimeSeries or floats.

spinetoolbox.plotting._filter_name_columns(selections)[source]

Returns a dict with all but the entry with the greatest key removed.

spinetoolbox.plotting._organize_selection_to_columns(indexes)[source]

Organizes a list of model indexes into a dictionary of {column: (rows)} entries.

spinetoolbox.plotting._collect_single_column_values(model, column, rows, hints)[source]

Collects selected parameter values from a single column.

The return value of this function depends on what type of data the given column contains. In case of plain numbers, a list of floats and a single label string are returned. In case of time series, a list of TimeSeries objects is returned, accompanied by a list of labels, each label corresponding to one of the time series.

Parameters:
  • model (QAbstractTableModel) – a table model
  • column (int) – a column index to the model
  • rows (Sequence) – row indexes to plot
  • hints (PlottingHints) – a plot support object
Returns:

a tuple of values and label(s)

spinetoolbox.plotting._collect_column_values(model, column, rows, hints)[source]

Collects selected parameter values from a single column for plotting.

The return value of this function depends on what type of data the given column contains. In case of plain numbers, a single tuple of two lists of x and y values and a single label string are returned. In case of time series, a list of TimeSeries objects is returned, accompanied by a list of labels, each label corresponding to one of the time series.

Parameters:
  • model (QAbstractTableModel) – a table model
  • column (int) – a column index to the model
  • rows (Sequence) – row indexes to plot
  • hints (PlottingHints) – a support object
Returns:

a tuple of values and label(s)

spinetoolbox.plotting._raise_if_value_types_clash(values, plot_widget)[source]

Raises a PlottingError if values type is incompatible with plot_widget.