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: |
|
---|---|
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
-
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:
-
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.
-
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.
-
-
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.
-
-
class
spinetoolbox.plotting.
PivotTablePlottingHints
[source]¶ Bases:
spinetoolbox.plotting.PlottingHints
Support for plotting data in Tabular view.
-
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.
-
-
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)