spinetoolbox.plotting
Functions for plotting on PlotWidget.
Module Contents
Classes
Generic enumeration. |
|
Two-dimensional data for plotting. |
|
A labeled node in tree structure. |
|
Header section info for Database editor's parameter tables. |
|
Functions
Converts indexed values to tree nodes recursively. |
|
|
Constructs plottable data and indexes recursively. |
|
Raises an exception if data has different x axis labels. |
|
Raises an exception if the types of x data don't match. |
|
Removes redundant indexes from given XYData. |
|
Combines data with same data indexes into the same x axis. |
|
Returns True if a single y-axis should be used. |
|
Returns a plot widget with plots of the given data. |
|
Plots all data on single y-axis. |
|
Plots all data as stacked lines. |
|
Plots all data as bars. |
|
Plots all data on two y-axes. |
Converts x-axis values to something matplotlib can handle. |
|
|
Creates plot settings suitable for time series step plots. |
|
Decides plot method and default keyword arguments based on XYData. |
|
Tests if a type looks like time stamp. |
|
Plots bar chart on axes but returns patches instead of bar container. |
|
Gives data with same x small offsets to prevent bar stacking. |
|
Removes plots and legend from plot widget. |
|
Limits the number of x tick labels in case x-axis consists of strings. |
|
Calculates a human-readable row number. |
|
Returns a plot widget with plots of the selected indexes. |
|
Returns a plot widget with plots of the selected indexes. |
|
Returns a plot widget with plots of the selected indexes. |
|
Returns a plot widget with plots of database manager parameter value items. |
|
Checks if pivot source model has x column. |
|
Gets node from the contents of root_node adding a new node if necessary. |
|
Gets parsed value from model. |
|
Gathers index names from pivot table. |
|
Calculates display row for pivot table. |
Converts parameter value to leaf TreeElement. |
|
|
Adds row information to PlottingError if it is raised in the with block. |
|
Adds an array plot to a plot widget. |
|
Adds a time series step plot to a plot widget. |
Attributes
- class spinetoolbox.plotting.PlotType[source]
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- exception spinetoolbox.plotting.PlottingError[source]
Bases:
Exception
An exception signalling failure in plotting.
Initialize self. See help(type(self)) for accurate signature.
- class spinetoolbox.plotting.ParameterTableHeaderSection[source]
Header section info for Database editor’s parameter tables.
- spinetoolbox.plotting.convert_indexed_value_to_tree(value)[source]
Converts indexed values to tree nodes recursively.
- Parameters
value (IndexedValue) – value to convert
- Returns
root node of the converted tree
- Return type
- Raises
ValueError – raised when leaf value couldn’t be converted to float
- spinetoolbox.plotting.turn_node_to_xy_data(root_node, y_label_position, index_names=None, indexes=None)[source]
Constructs plottable data and indexes recursively.
- Parameters
root_node (TreeNode) – root node
y_label_position (int, optional) – position of y label in indexes
index_names (list of IndexName, optional) – list of current index names
indexes (list) – list of current indexes
- Yields
XYData – plot data
- spinetoolbox.plotting.raise_if_not_common_x_labels(data_list)[source]
Raises an exception if data has different x axis labels.
- Parameters
data_list (list of XYData) – data to check
- Raises
PlottingError – raised if x axis labels don’t match.
- spinetoolbox.plotting.raise_if_incompatible_x(data_list)[source]
Raises an exception if the types of x data don’t match.
- Parameters
data_list (list of XYData) – data to check
- Raises
PlottingError – raised if x data types don’t match.
- spinetoolbox.plotting.reduce_indexes(data_list)[source]
Removes redundant indexes from given XYData.
- Parameters
data_list (list of XYData) – data to reduce
- Returns
reduced data list and list of common data indexes
- Return type
tuple
- spinetoolbox.plotting.combine_data_with_same_indexes(data_list)[source]
Combines data with same data indexes into the same x axis.
- Parameters
data_list (list of XYData) – data to combine
- Returns
combined data
- Return type
list of XYData
- spinetoolbox.plotting._always_single_y_axis(plot_type)[source]
Returns True if a single y-axis should be used.
- Parameters
plot_type (PlotType) – plot type
- Returns
True if single y-axis is required, False otherwise
- Return type
bool
- spinetoolbox.plotting.plot_data(data_list, plot_widget=None, plot_type=None)[source]
Returns a plot widget with plots of the given data.
- Parameters
data_list (list of XYData) – data to plot
plot_widget (PlotWidget, optional) – an existing plot widget to draw into or None to create a new widget
plot_type (PlotType, optional) – plot type
- Returns
a PlotWidget object
- spinetoolbox.plotting._plot_single_y_axis(data_list, y_label, axes, plot_type)[source]
Plots all data on single y-axis.
- Parameters
data_list (list of XYData) – data to plot
y_label (str) – y-axis label
axes (Axes) – plot axes
plot_type (PlotType) – plot type
- Returns
legend handles
- Return type
list
- spinetoolbox.plotting._plot_stacked_line(data_list, y_label, axes)[source]
Plots all data as stacked lines.
- Parameters
data_list (list of XYData) – data to plot
y_label (str) – y-axis label
axes (Axes) – plot axes
- Returns
legend handles
- Return type
list
- spinetoolbox.plotting._plot_bar(data_list, y_label, axes)[source]
Plots all data as bars.
- Parameters
data_list (list of XYData) – data to plot
y_label (str) – y-axis label
axes (Axes) – plot axes
- Returns
legend handles
- Return type
list
- spinetoolbox.plotting._plot_double_y_axis(data_list, y_labels, plot_widget, plot_type)[source]
Plots all data on two y-axes.
- Parameters
data_list (list of XYData) – data to plot
y_labels (list of str) – y-axis labels
plot_widget (PlotWidget) – plot widget
plot_type (PlotType) – plot type
- Returns
legend handles
- Return type
list
- spinetoolbox.plotting._make_x_plottable(xs)[source]
Converts x-axis values to something matplotlib can handle.
- Parameters
xs (list) – x values
- Returns
x values
- Return type
list
- spinetoolbox.plotting._make_time_series_settings(plot_settings)[source]
Creates plot settings suitable for time series step plots.
- Parameters
plot_settings (dict) – base plot settings
- Returns
time series step plot settings
- Return type
dict
- spinetoolbox.plotting._make_plot_function(plot_type, x_data_type, axes)[source]
Decides plot method and default keyword arguments based on XYData.
- Parameters
plot_type (PlotType) – plot type
x_data_type (Type) – data type of x-axis
axes (Axes) – plot axes
- Returns
plot method
- Return type
Callable
- spinetoolbox.plotting._is_time_stamp_type(data_type)[source]
Tests if a type looks like time stamp.
- Parameters
data_type (Type) – data type to test
- Returns
True if type is a time stamp type, False otherwise
- Return type
bool
- spinetoolbox.plotting._bar(x, y, axes, **kwargs)[source]
Plots bar chart on axes but returns patches instead of bar container.
- Parameters
x (Any) – x data
y (Any) – y data
axes (Axes) – plot axes
**kwargs – keyword arguments passed to bar()
- Returns
patches
- Return type
list of Patch
- spinetoolbox.plotting._group_bars(data_list)[source]
Gives data with same x small offsets to prevent bar stacking.
- Parameters
data_list (List of XYData) – squeezed data
- Returns
grouped data, bar width and x ticks
- Return type
tuple
- spinetoolbox.plotting._clear_plot(plot_widget)[source]
Removes plots and legend from plot widget.
- Parameters
plot_widget (PlotWidget) – plot widget
- spinetoolbox.plotting._limit_string_x_tick_labels(data, plot_widget)[source]
Limits the number of x tick labels in case x-axis consists of strings.
Matplotlib tries to plot every single x tick label if they are strings. This can become very slow if the labels are numerous.
- Parameters
data (list of XYData) – plot data
plot_widget (PlotWidget) – plot widget
- spinetoolbox.plotting._table_display_row(row)[source]
Calculates a human-readable row number.
- Parameters
row (int) – model row
- Returns
row number
- Return type
int
- spinetoolbox.plotting.plot_parameter_table_selection(model, model_indexes, table_header_sections, value_section_label, plot_widget=None)[source]
Returns a plot widget with plots of the selected indexes.
- Parameters
model (QAbstractTableModel) – a model
model_indexes (Iterable of QModelIndex) – a list of QModelIndex objects for plotting
table_header_sections (list of ParameterTableHeaderSection) – table header labels
value_section_label (str) – value column’s header label
plot_widget (PlotWidget, optional) – an existing plot widget to draw into or None to create a new widget
- Returns
a PlotWidget object
- Return type
- spinetoolbox.plotting.plot_value_editor_table_selection(model, model_indexes, plot_widget=None)[source]
Returns a plot widget with plots of the selected indexes.
- Parameters
model (QAbstractTableModel) – a model
model_indexes (Iterable of QModelIndex) – a list of QModelIndex objects for plotting
plot_widget (PlotWidget, optional) – an existing plot widget to draw into or None to create a new widget
- Returns
a PlotWidget object
- Return type
- spinetoolbox.plotting.plot_pivot_table_selection(model, model_indexes, plot_widget=None)[source]
Returns a plot widget with plots of the selected indexes.
- Parameters
model (QAbstractTableModel) – a model
model_indexes (Iterable of QModelIndex) – a list of QModelIndex objects for plotting
plot_widget (PlotWidget, optional) – an existing plot widget to draw into or None to create a new widget
- Returns
a PlotWidget object
- Return type
- spinetoolbox.plotting.plot_db_mngr_items(items, db_maps, plot_widget=None)[source]
Returns a plot widget with plots of database manager parameter value items.
- Parameters
items (list of dict) – parameter value items
db_maps (list of DatabaseMapping) – database mappings corresponding to items
plot_widget (PlotWidget, optional) – widget to add plots to
- spinetoolbox.plotting._has_x_column(model, source_model)[source]
Checks if pivot source model has x column.
- Parameters
model (PivotTableSortFilterProxy) – proxy pivot model
source_model (PivotTableModelBase) – pivot table model
- Returns
True if x pivot table has column, False otherwise
- Return type
bool
- spinetoolbox.plotting._set_default_node(root_node, key, label)[source]
Gets node from the contents of root_node adding a new node if necessary.
- spinetoolbox.plotting._get_parsed_value(model_index, display_row)[source]
Gets parsed value from model.
- Parameters
model_index (QModelIndex) – model index
display_row (Callable) – callable that returns a display row
- Returns
parsed value
- Return type
Any
- Raises
PlottingError – raised if parsing of value failed
- spinetoolbox.plotting._pivot_index_names(indexes)[source]
Gathers index names from pivot table.
- Parameters
indexes (tuple of str) – “path” of indexes
- Returns
names corresponding to given indexes
- Return type
tuple of str
- spinetoolbox.plotting._pivot_display_row(row, source_model)[source]
Calculates display row for pivot table.
- Parameters
row (int) – row in source table model
source_model (QAbstractItemModel) – pivot model
- Returns
human-readable row number
- Return type
int
- spinetoolbox.plotting._convert_to_leaf(y)[source]
Converts parameter value to leaf TreeElement.
- Parameters
y (Any) – parameter value
- Returns
leaf element
- Return type
float or datetime or TreeNode
- spinetoolbox.plotting.add_row_to_exception(row, display_row)[source]
Adds row information to PlottingError if it is raised in the with block.
- Parameters
row (int) – row
display_row (Callable) – function to convert row to display row
- spinetoolbox.plotting.add_array_plot(plot_widget, value)[source]
Adds an array plot to a plot widget.
- Parameters
plot_widget (PlotWidget) – a plot widget to modify
value (Array) – the array to plot
- spinetoolbox.plotting.add_time_series_plot(plot_widget, value)[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