This module contains a widget to create new plots with psyplot

The main class is the PlotCreator which is used to handle the different plotting methods of the psyplot.project.ProjectPlotter class

Classes:

ArrayNameItemDelegate

Delegate using the ArrayNameValidator for validation

ArrayNameValidator(text, table, *args, **kwargs)

Class to make sure that only those arrays names are inserted that are not currently in the main project or the tree

ArrayTable(get_func[, columns])

Table that shows the arrays that will be used for plotting

AxesCreator([fig, x0, y0, x1, y1])

Widget to setup an axes in a arbitrary location

AxesCreatorCollection([key, func_kwargs])

Wrapper for a QToolBox that holds the different possibilities to select an axes

AxesSelector(*args, **kwargs)

Widget to select an already created axes

AxesViewer(*args, **kwargs)

Widget to show a rectangle

CoordComboBox(ds_func, dim[, parent])

Combobox showing coordinate information of a dataset

CoordsTable(get_func, *args, **kwargs)

A table showing the coordinates of in a dataset via instances of CoordComboBox

DragDropTable(*args, **kwargs)

Table that allows to exchange rows via drag and drop

PlotCreator(*args, **kwargs)

Widget to extract data from a dataset and eventually create a plot

SubplotCreator([fig, rows, cols, num1, num2])

Select a subplot to which will be created (if not already existing) when making the plot

VariableItemDelegate

Delegate alowing only the variables in the parents dataset.

VariablesTable(get_func[, columns])

Table to display the variables of a dataset

class psyplot_gui.plot_creator.ArrayNameItemDelegate[source]

Bases: QStyledItemDelegate

Delegate using the ArrayNameValidator for validation

Methods:

createEditor(self, parent, option, index)

createEditor(self, parent: QWidget | None, option: QStyleOptionViewItem, index: QModelIndex) QWidget | None[source]
class psyplot_gui.plot_creator.ArrayNameValidator(text, table, *args, **kwargs)[source]

Bases: QValidator

Class to make sure that only those arrays names are inserted that are not currently in the main project or the tree

Methods:

fixup(self, a0)

validate(self, a0, a1)

fixup(self, a0: str | None) str[source]
validate(self, a0: str | None, a1: int)[source]
class psyplot_gui.plot_creator.ArrayTable(get_func, columns=[], *args, **kwargs)[source]

Bases: DragDropTable

Table that shows the arrays that will be used for plotting

It contains the following columns:

  1. The variable column which holds the variable names of the arrays. multiple variables may be separated by ‘;;’

  2. The array name. The psyplot.data.InteractiveBase.arr_name attribute. Depending on the plot methods _prefer_list, multiple array names are allowed or not. If this attribute is True, arrays with the same array name will be concatenated into one psyplot.data.InteractiveList

  3. The axes column. Use the right-click context menu to select a subplot

  4. The check column. Checks for variable names, array names, axes and dimensions via the psyplot.project._PlotterInterface.check_data() method

  5. Columns containing the dimension informations

Attributes:

DIMS_TT

Base tool tip for a dimension column

VARIABLE_TT

Tool tip for the variable column

arr_col

The index of the array name column

arr_names_dict

The final dictionary containing the array names necessary for the arr_names parameter in the psyplot.data.ArrayList.from_dataset() method

axes

A list of axes settings corresponding to the arrays in the arr_names_dict

axes_col

The index of the axes column

axes_patt

pattern to interprete arbitrary axes

check_col

The index of the check column

current_names

The names that are currently in use

prefer_list

Return the _prefer_list attribute of the plot_method

sep

The separator for variable names

subplot_patt

Pattern to interprete subplots

var_col

The index of the variable column

vnames

The list of variable names per array

Methods:

add_single_subplot(rows, cols, row, col)

Add one subplot to the selected arrays on multiple figures

add_subplots(rows, cols[, maxn])

Add multiple subplots to the selected arrays

axes_creator_action(rows)

Action to open a AxesCreatorCollection for the selected rows

axes_info(s)

Interpretes an axes information

check_array(row[, ignore_duplicates])

check whether the array variables are valid, the array name is valid, the axes info is valid and the dimensions

check_arrays(**kwargs)

Convenience function to check all arrays using the check_array() method

check_item(item)

Check the array corresponding to the given item

dropEvent(event)

Reimplemented to call the check_arrays() after the call

get_all_rows(row)

Return all the rows that have the same array name as the given row

insert_array(name[, check])

Appends the settings for an array the the list in a new row

next_available_name(*args, **kwargs)

Gives the next possible name to use

remove_arrays([selected])

Remove array rows from the list

set_columns(columns)

Set the columns of the table

set_pm(s)

Set the plot method

setup_from_ds([ds, plot_method])

Fill the table based upon the given dataset.

showAxesCreator(pos)

Context menu for right-click on a row

update_other_items(item)

Updates the axes information of the other items corresponding that have the same array name as the array corresponding to the given item

update_selected([check, dims])

Updates the dimensions of the selectiond arrays with the given dims

DIMS_TT = "The values for dimension %s. You can use integers either explicit, e.g.<ul><li>1, 2, 3, ...,</li></ul>or slices like <em>start:end:step</em>, e.g.<ul><li>'1:6:2'</li></ul>where the latter is equivalent to '1, 3, 5'"

Base tool tip for a dimension column

VARIABLE_TT = "The variables of the array from the dataset. Multiplevariables for one array may be separated by ';;'"

Tool tip for the variable column

add_single_subplot(rows, cols, row, col)[source]

Add one subplot to the selected arrays on multiple figures

add_subplots(rows, cols, maxn=None)[source]

Add multiple subplots to the selected arrays

property arr_col

The index of the array name column

property arr_names_dict

The final dictionary containing the array names necessary for the arr_names parameter in the psyplot.data.ArrayList.from_dataset() method

property axes

A list of axes settings corresponding to the arrays in the arr_names_dict

property axes_col

The index of the axes column

axes_creator_action(rows)[source]

Action to open a AxesCreatorCollection for the selected rows

axes_info(s)[source]

Interpretes an axes information

axes_patt = re.compile('\\((?P<fig>\\d+),\\s*(?P<x0>0*\\.\\d+),\\s*(?P<y0>0*\\.\\d+),\\s*(?P<x1>0*\\.\\d+),\\s*(?P<y1>0*\\.\\d+)\\s*\\)')

pattern to interprete arbitrary axes

check_array(row, ignore_duplicates=[])[source]

check whether the array variables are valid, the array name is valid, the axes info is valid and the dimensions

check_arrays(**kwargs)[source]

Convenience function to check all arrays using the check_array() method

property check_col

The index of the check column

check_item(item)[source]

Check the array corresponding to the given item

property current_names

The names that are currently in use

dropEvent(event)[source]

Reimplemented to call the check_arrays() after the call

get_all_rows(row)[source]

Return all the rows that have the same array name as the given row

insert_array(name, check=True, **kwargs)[source]

Appends the settings for an array the the list in a new row

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

Gives the next possible name to use

property prefer_list

Return the _prefer_list attribute of the plot_method

remove_arrays(selected=True)[source]

Remove array rows from the list

Parameters:

selected (bool) – If True, only the selected rows are removed

sep = ';;'

The separator for variable names

set_columns(columns)[source]

Set the columns of the table

Parameters:

columns (list of str) – The coordinates in the dataset

set_pm(s)[source]

Set the plot method

setup_from_ds(ds=None, plot_method=None)[source]

Fill the table based upon the given dataset.

Parameters:
  • ds (xarray.Dataset or None) – If None, the dataset from the get_ds function is used

  • plot_method (psyplot.project._PlotterInterface or None) – The plot method of the psyplot.project.ProjectPlotter class or None if no plot shall be made

showAxesCreator(pos)[source]

Context menu for right-click on a row

subplot_patt = re.compile('\\((?P<fig>\\d+),\\s*(?P<rows>\\d+),\\s*(?P<cols>\\d+),\\s*(?P<num1>\\d+),\\s*(?P<num2>\\d+)\\s*\\)')

Pattern to interprete subplots

update_other_items(item)[source]

Updates the axes information of the other items corresponding that have the same array name as the array corresponding to the given item

update_selected(check=True, dims={})[source]

Updates the dimensions of the selectiond arrays with the given dims

Parameters:
  • check (bool) – whether the array shall be checked afterwards

  • dims (dict) – a mapping from coordinate names to string values that shall be appended to the current text

property var_col

The index of the variable column

property vnames

The list of variable names per array

class psyplot_gui.plot_creator.AxesCreator(fig=None, x0=0.125, y0=0.1, x1=0.9, y1=0.9, *args, **kwargs)[source]

Bases: QWidget

Widget to setup an axes in a arbitrary location

Methods:

create_axes(fig, x0, y0, x1, y1, **kwargs)

Create an axes for the given fig

get_iter()

Get the iterator over the axes

resize_rectangle(size)

resize the rectangle after changes of the widget size

static create_axes(fig, x0, y0, x1, y1, **kwargs)[source]

Create an axes for the given fig

Parameters:
  • fig (int or None) – The figure number. If None, a new figure number will be used

  • x0 (float) – the x-coordinate of the lower left corner (between 0 and 1)

  • y0 (float) – the y-coordinate of the lower left corner (between 0 and 1)

  • x1 (float) – the x-coordinate of the upper right corner (between 0 and 1)

  • y1 (float) – the y-coordinate of the upper right corner (between 0 and 1)

  • **kwargs – Any other keyword argument for the matplotlib.figure.Figure.add_axes() method

get_iter()[source]

Get the iterator over the axes

resize_rectangle(size)[source]

resize the rectangle after changes of the widget size

class psyplot_gui.plot_creator.AxesCreatorCollection(key=None, func_kwargs={}, *args, **kwargs)[source]

Bases: QDialog

Wrapper for a QToolBox that holds the different possibilities to select an axes

When the user finished, the okpressed symbol is emitted with an infinite iterator of strings. Possible widgets for the toolbox are determined by the widgets attribute

Methods:

close()

reimplemented to make sure that all widgets are closed when this one is closed

create_subplot()

Method that is called whenn the ok button is pressed.

Attributes:

okpressed(*args, **kwargs)

signal that is emitted when the 'Ok' pushbutton is pressed and the user finished the selection

widgets

key, title and class fot the widget that is used to create an axes

close()[source]

reimplemented to make sure that all widgets are closed when this one is closed

create_subplot()[source]

Method that is called whenn the ok button is pressed.

It emits the okpressed signal with the iterator of the current widget in the toolbox

okpressed(*args, **kwargs)

signal that is emitted when the ‘Ok’ pushbutton is pressed and the user finished the selection

widgets = [('subplot', 'Subplot in a grid', <class 'psyplot_gui.plot_creator.SubplotCreator'>), ('axes', 'Arbitray position', <class 'psyplot_gui.plot_creator.AxesCreator'>), ('choose', 'Existing subplot', <class 'psyplot_gui.plot_creator.AxesSelector'>)]

key, title and class fot the widget that is used to create an axes

class psyplot_gui.plot_creator.AxesSelector(*args, **kwargs)[source]

Bases: QWidget

Widget to select an already created axes

Click the button, select your axes and click the button again

Methods:

allow_axes_select()

Replace make all axes pickable

change_pickers(b)

Change the pickers of the axes instances

close()

Reimplemented to restore the pickers if the widget is closed

get_iter()

Get the iterator over the axes

get_picked_ax(event)

Function to be called when an axes is picked

inspect_axes(ax)

Inspect the given axes and get the right string for making a plot with it

restore_pickers()

Restore the original pickers of the existing axes instances

setVisible(b)

Reimplemented to restore the pickers if the widget is made invisible

unclick()

Restore the original pickers

allow_axes_select()[source]

Replace make all axes pickable

change_pickers(b)[source]

Change the pickers of the axes instances

If the push button is clicked, we replace the existing pickers of the axes in order to select the plots. Otherwise we restore them

close()[source]

Reimplemented to restore the pickers if the widget is closed

get_iter()[source]

Get the iterator over the axes

get_picked_ax(event)[source]

Function to be called when an axes is picked

inspect_axes(ax)[source]

Inspect the given axes and get the right string for making a plot with it

restore_pickers()[source]

Restore the original pickers of the existing axes instances

setVisible(b)[source]

Reimplemented to restore the pickers if the widget is made invisible

unclick()[source]

Restore the original pickers

class psyplot_gui.plot_creator.AxesViewer(*args, **kwargs)[source]

Bases: QGraphicsView

Widget to show a rectangle

Methods:

resizeEvent(self, event)

Attributes:

sizeChanged(*args, **kwargs)

resizeEvent(self, event: QResizeEvent | None)[source]
sizeChanged(*args, **kwargs)
class psyplot_gui.plot_creator.CoordComboBox(ds_func, dim, parent=None)[source]

Bases: QComboBox

Combobox showing coordinate information of a dataset

This combobox loads its data from the current dataset and allows the popups to be left open. It also has a leftclick signal that is emitted when the popup is about to be closed because the user clicked on a value

Attributes:

close_popups

leftclick(*args, **kwargs)

use_coords

Methods:

eventFilter(obj, event)

Reimplemented to filter right-click events on the view()

handleItemPressed(index)

Function to be called when an item is pressed to make sure that we know whether anything changed before closing the popup

hidePopup()

Reimplemented to only close the popup when the close_popup attribute is True or it is clicked outside the window

hide_anyway([index])

Function to hide the popup despite of the _changed attribute

load_coord()

Load the coordinate data from the dataset and fill the combobox with it (if it is empty)

mouseDoubleClickEvent(*args, **kwargs)

Reimplemented to fill the box with content from the dataset

mousePressEvent(*args, **kwargs)

Reimplemented to fill the box with content from the dataset

right_click(point)

Function that is called when an item is right_clicked

property close_popups
eventFilter(obj, event)[source]

Reimplemented to filter right-click events on the view()

handleItemPressed(index)[source]

Function to be called when an item is pressed to make sure that we know whether anything changed before closing the popup

hidePopup()[source]

Reimplemented to only close the popup when the close_popup attribute is True or it is clicked outside the window

hide_anyway(index=None)[source]

Function to hide the popup despite of the _changed attribute

leftclick(*args, **kwargs)
load_coord()[source]

Load the coordinate data from the dataset and fill the combobox with it (if it is empty)

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

Reimplemented to fill the box with content from the dataset

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

Reimplemented to fill the box with content from the dataset

right_click(point)[source]

Function that is called when an item is right_clicked

property use_coords
class psyplot_gui.plot_creator.CoordsTable(get_func, *args, **kwargs)[source]

Bases: QTableWidget

A table showing the coordinates of in a dataset via instances of CoordComboBox

Attributes:

combo_boxes

A list of CoordComboBox in this table

Methods:

fill_from_ds([ds])

Clear the table and create new comboboxes

sizeHint()

Reimplemented to adjust the heigth based upon the header and the first row

property combo_boxes

A list of CoordComboBox in this table

fill_from_ds(ds=None)[source]

Clear the table and create new comboboxes

sizeHint()[source]

Reimplemented to adjust the heigth based upon the header and the first row

class psyplot_gui.plot_creator.DragDropTable(*args, **kwargs)[source]

Bases: QTableWidget

Table that allows to exchange rows via drag and drop

This class was mainly taken from http://stackoverflow.com/questions/26227885/drag-and-drop-rows-within-qtablewidget

Methods:

dropEvent(self, event)

dropOn(event)

droppingOnItself(event, index)

moveRows(row[, remove])

Move all selected rows to the given row

position(pos, rect, index)

dropEvent(self, event: QDropEvent | None)[source]
dropOn(event)[source]
droppingOnItself(event, index)[source]
moveRows(row, remove=False)[source]

Move all selected rows to the given row

position(pos, rect, index)[source]
class psyplot_gui.plot_creator.PlotCreator(*args, **kwargs)[source]

Bases: QDialog

Widget to extract data from a dataset and eventually create a plot

Attributes:

NO_PM_TT

Tooltip for not making a plot

Methods:

add_new_ds(oname, ds[, fname])

close(*args, **kwargs)

Reimplemented to make sure that the data sets are deleted

connect_combo_boxes()

create_plots()

Method to be called when the Create plot button is pressed

fill_ds_combo(project)

fill the dataset combobox with datasets of the current main project

fill_fmt_tree(pm)

fill_plot_method_combo()

Takes the names of the plotting methods in the current project

get_ds([i])

Get the dataset

insert_array([variables])

Inserts an array for the given variables (or the ones selected in the variable_table if variables is None)

insert_array_from_combo(cb[, variables])

Insert new arrays into the dataset when the combobox is left-clicked

keyPressEvent(e)

Reimplemented to close the window when escape is hitted

load_preset()

Load a preset file

open_data(*args, **kwargs)

Convenience method to create a sub project without a plotter

open_dataset([fnames])

Opens a file dialog and the dataset that has been inserted

reset_comboboxes()

Clear all comboboxes

set_decoder(decoder)

Set the decoder for the new plots.

set_ds(i)

Set the current dataset

set_pm(plot_method)

set_preset(preset)

setup_subplot()

Method to be emitted to setup one subplot at a specific location for each of the selected arrays on separate (new) figures

setup_subplots()

Method to be emitted to setup the subplots for the selected arrays on new figures

show_pm_info()

Shows info on the current plotting method in the help explorer

switch2ds(ds)

Switch to the given dataset

toggle_close_popups()

Change the automatic closing of popups

NO_PM_TT = 'Choose a plot method (or choose none to only extract the data)'

Tooltip for not making a plot

add_new_ds(oname, ds, fname=None)[source]
close(*args, **kwargs)[source]

Reimplemented to make sure that the data sets are deleted

connect_combo_boxes()[source]
create_plots()[source]

Method to be called when the Create plot button is pressed

This method reads the data from the array_table attribute and makes the plot (or extracts the data) based upon the plot_method attribute

fill_ds_combo(project)[source]

fill the dataset combobox with datasets of the current main project

fill_fmt_tree(pm)[source]
fill_plot_method_combo()[source]

Takes the names of the plotting methods in the current project

get_ds(i=None)[source]

Get the dataset

Parameters:

i (int or None) – If None, the dataset of the current index in the ds_combo is returned. Otherwise it specifies the locdation of the dictionary in the ds_descs attribute

Returns:

The requested dataset

Return type:

xarray.Dataset

insert_array(variables=None)[source]

Inserts an array for the given variables (or the ones selected in the variable_table if variables is None)

insert_array_from_combo(cb, variables=None)[source]

Insert new arrays into the dataset when the combobox is left-clicked

keyPressEvent(e)[source]

Reimplemented to close the window when escape is hitted

load_preset()[source]

Load a preset file

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

Convenience method to create a sub project without a plotter

This method is used when the pm_combo is empty

open_dataset(fnames=None, *args, **kwargs)[source]

Opens a file dialog and the dataset that has been inserted

reset_comboboxes()[source]

Clear all comboboxes

set_decoder(decoder)[source]

Set the decoder for the new plots.

set_ds(i)[source]

Set the current dataset

set_pm(plot_method)[source]
set_preset(preset)[source]
setup_subplot()[source]

Method to be emitted to setup one subplot at a specific location for each of the selected arrays on separate (new) figures

setup_subplots()[source]

Method to be emitted to setup the subplots for the selected arrays on new figures

show_pm_info()[source]

Shows info on the current plotting method in the help explorer

switch2ds(ds)[source]

Switch to the given dataset

Parameters:

ds (xarray.Dataset) – The dataset to use. It is assumed that this dataset is already in the dataset combobox

toggle_close_popups()[source]

Change the automatic closing of popups

class psyplot_gui.plot_creator.SubplotCreator(fig=None, rows=1, cols=1, num1=1, num2=None, *args, **kwargs)[source]

Bases: QWidget

Select a subplot to which will be created (if not already existing) when making the plot

Methods:

create_subplot([fig, rows, cols, num1, num2])

Create a subplot for the given figure

get_iter()

Get the iterator over the axes

set_num2_validator(s)

Set the validator range for the num2 line edit

set_selected(num1, num2)

Update the selection in the table based upon num1 and num2

set_selected_from_num1(s)

Update the selection of the table after changes of num1_edit

set_selected_from_num2(s)

Update the selection of the table after changes of num2_edit

setup_table()

Set up the table based upon the number of rows and columns in the rows and cols line edit

update_num_edit()

Update the num1_edit and num2_edit after the selection of the table changed

static create_subplot(fig=None, rows=1, cols=1, num1=1, num2=None, **kwargs)[source]

Create a subplot for the given figure

Parameters:
  • fig (matplotlib.figure.Figure or int) – If integer, the matplotlib.pyplot.figure() function is used

  • rows (int) – Number of rows for the gridspec

  • cols (int) – Number of columns for the gridspec

  • num1 (int) – The subplot number of the upper left corner in the grid (starting from 1!)

  • num2 (None or int) – The subplot number of the lower left corner in the grid (starting from 1!). If None, num1 will be used

  • **kwargs – Any other keyword argument for the matplotlib.figure.Figure.add_subplot() method

Returns:

The new created subplot

Return type:

mpl.axes.Subplot

get_iter()[source]

Get the iterator over the axes

set_num2_validator(s)[source]

Set the validator range for the num2 line edit

set_selected(num1, num2)[source]

Update the selection in the table based upon num1 and num2

set_selected_from_num1(s)[source]

Update the selection of the table after changes of num1_edit

set_selected_from_num2(s)[source]

Update the selection of the table after changes of num2_edit

setup_table()[source]

Set up the table based upon the number of rows and columns in the rows and cols line edit

update_num_edit()[source]

Update the num1_edit and num2_edit after the selection of the table changed

class psyplot_gui.plot_creator.VariableItemDelegate[source]

Bases: QStyledItemDelegate

Delegate alowing only the variables in the parents dataset.

The parent must hold a get_ds method that returns a dataset when called

Methods:

createEditor(self, parent, option, index)

createEditor(self, parent: QWidget | None, option: QStyleOptionViewItem, index: QModelIndex) QWidget | None[source]
class psyplot_gui.plot_creator.VariablesTable(get_func, columns=['long_name', 'dims', 'shape'], *args, **kwargs)[source]

Bases: QTableWidget

Table to display the variables of a dataset

Methods:

fill_from_ds([ds])

Clear the table and insert items from the given dataset

set_columns([columns])

Attributes:

selected_variables

The currently selected variables

variables

The variables in the dataset

fill_from_ds(ds=None)[source]

Clear the table and insert items from the given dataset

property selected_variables

The currently selected variables

set_columns(columns=None)[source]
variables = []

The variables in the dataset