Plotmethod widgets.

This module defines the widgets to interface with the mapplot, plot2d and lineplot plotmethods.

Classes:

GridCell(qobject[, column, colspan, stretch])

A grid cell within a QGridLayout managing one QWidget.

LinePlotWidget(get_sp, ds)

A widget to control the lineplot plotmethod.

MapPlotWidget(get_sp, ds)

A widget to control the mapplot plotmethod.

Plot2DWidget(get_sp, ds)

A widget to control the plot2d plotmethod.

PlotMethodWidget(get_sp, ds)

Base class for interfacing a psyplot plotmethod.

PlotType(value)

A value for the 2D plot formatoption.

QHLine()

A horizontal seperation line.

Data:

projection_map

A mapping from projection identifier to the text we want to use in the GUI

class psy_view.plotmethods.GridCell(qobject: QWidget | QLayout, column: int | None = None, colspan: int = 1, stretch: bool = False)[source]

Bases: object

A grid cell within a QGridLayout managing one QWidget.

Attributes:

colspan

The number of columns to cover

column

The starting column for the widget.

qobject

the PyQt5.QtWidgets.QWidget instance (i.e. the widget) or a layout (PyQt5.QtWidgets.QLayout).

stretch

A boolean whether to add stretch or not

Methods:

from_alias(o[, c, cs, s])

Create a GridCell from shorter kws.

colspan: int = 1

The number of columns to cover

column: int | None = None

The starting column for the widget. If None, it will be estimated based on the other widgets in the row

classmethod from_alias(o: QWidget | QLayout, c: int | None = None, cs: int = 1, s: bool = False) T[source]

Create a GridCell from shorter kws.

Parameters:
  • o (QWidget or QLayout) – The alias for qobject

  • c (int or None, optional) – The alias for column

  • cs (int, optional) – The alias for colspan

  • s (bool, optional) – The alias for stretch

Returns:

The generated instance of GridCell

Return type:

GridCell

qobject: QWidget | QLayout

the PyQt5.QtWidgets.QWidget instance (i.e. the widget) or a layout (PyQt5.QtWidgets.QLayout)

stretch: bool = False

A boolean whether to add stretch or not

class psy_view.plotmethods.LinePlotWidget(get_sp: Callable[[], Project | None], ds: Dataset | None)[source]

Bases: PlotMethodWidget

A widget to control the lineplot plotmethod.

Methods:

add_line([name])

Add a line to the plot.

block_combos()

Temporarilly block any signal of the combo boxes.

edit_labels()

Open the dialog to edit the text labels in the plot.

get_rows(func)

Get the rows of the formatoption widgets.

init_dims(var)

Get the formatoptions for a new plot.

refresh(ds)

Refresh this widget from the given dataset.

remove_line()

Remove the current line from the plot.

setEnabled(b)

Enable or disable the datagrid and color buttons.

setup_dimension_combo()

Set up the combobox for selecting the x-dimension.

setup_labels_button()

Add a button to modify the text labels.

setup_line_selection()

Setup the row for selecting new lines.

valid_variables(ds)

Get a list of variables that can be visualized with this plotmethod.

Attributes:

data

The first array in the list.

fmt_setup_functions

Get a list of rows for formatoptions.

item_texts

Get the labels for the individual lines.

plotmethod

xdim

Get the x-dimension for the plot.

add_line(name: Hashable | None = None, **sl) None[source]

Add a line to the plot.

This method adds a new line for the plot specified by the given name of the variable and the slices.

Parameters:
  • name (str) – The variable name to display

  • **sl – The slices to turn the name variable into a 1D-array.

block_combos() Iterator[None][source]

Temporarilly block any signal of the combo boxes.

property data: DataArray

The first array in the list.

edit_labels() None[source]

Open the dialog to edit the text labels in the plot.

property fmt_setup_functions: List[Callable]

Get a list of rows for formatoptions.

This property returns a list of callable. Each callable should setup a horizonal (or widget) that is added to the layout vbox.

get_rows(func: Callable) List[List[GridCell]][source]

Get the rows of the formatoption widgets.

This method should take callable from the fmt_setup_functions list and return the rows corresponding to formatoption_rows.

init_dims(var: DataArray) Dict[Hashable | str | Any, Any][source]

Get the formatoptions for a new plot.

Parameters:

var (xarray.Variable) – The variable in the base dataset

Returns:

A mapping from formatoption or dimension to the corresponding value for the plotmethod.

Return type:

dict

property item_texts: List[str]

Get the labels for the individual lines.

plotmethod: ClassVar[str] = 'lineplot'
refresh(ds) None[source]

Refresh this widget from the given dataset.

remove_line() None[source]

Remove the current line from the plot.

setEnabled(b: bool) None[source]

Enable or disable the datagrid and color buttons.

Parameters:

b (bool) – If True, enable the buttons, else disable.

setup_dimension_combo() None[source]

Set up the combobox for selecting the x-dimension.

setup_labels_button() None[source]

Add a button to modify the text labels.

setup_line_selection() None[source]

Setup the row for selecting new lines.

valid_variables(ds: Dataset) List[Hashable][source]

Get a list of variables that can be visualized with this plotmethod.

Parameters:

ds (xarray.Dataset) – The dataset to use

Returns:

List of variable names to plot

Return type:

list of str

property xdim: str

Get the x-dimension for the plot.

class psy_view.plotmethods.MapPlotWidget(get_sp: Callable[[], Project | None], ds: Dataset | None)[source]

Bases: PlotMethodWidget

A widget to control the mapplot plotmethod.

Methods:

block_combos()

Temporarilly block any signal of the coord_combos.

choose_next_projection()

Choose the next projection from the rcParams projection value.

edit_basemap_settings()

Open a dialog to edit the basemap and projection settings.

edit_color_settings()

Open the dialog to edit the color settings.

edit_labels()

Open the dialog to edit the text labels in the plot.

fix_data()

Call the fix_lonlatbox method of all map plotters.

fix_extent()

Call the fix_map_extent method of all map plotters.

get_fmts(var[, init])

Get the formatoptions for a new plot.

get_projection_label(proj)

Get the label for a projection in the GUI.

get_projection_value(label)

Get the value for the projection formatoption.

get_rows(func)

Get the rows of the formatoption widgets.

get_slice(x, y)

Get the slice for the selected coordinates.

init_dims(var)

Get the formatoptions for a new plot.

open_cmap_dialog([N])

Open the dialog to change the colormap.

refresh(ds)

Refresh this widget from the given dataset.

refresh_from_sp()

Refresh this widget from the plotters project.

reset_extent_and_lonlatbox()

Reset the extent and the lonlatbox to the defaults.

setEnabled(b)

Enable or disable the projection and color buttons.

set_cmap(cmap)

Update the plotter with the given colormap.

set_combo_text(combo, text)

Convenience function to update set the current text of a combobox.

set_plot_type(plot_type)

Update the value for the plot formatoption

set_projection(proj)

Update the projection of the plot with the given projection.

set_xcoord(text)

Set the name of the x-coordinate.

set_ycoord(text)

Set the name of the y-coordinate.

setup_cmap_menu()

Set up the menu to change the colormaps.

setup_color_buttons()

Set up the buttons to change the colormap, etc.

setup_dimension_box()

Set up a box to control, what is the x and y-dimension.

setup_fix_extent_buttons()

Setup the buttons for fixing the extent or data

setup_labels_button()

Add a button to modify the text labels.

setup_plot_buttons()

Setup the second row of formatoption widgets.

setup_projection_buttons()

Set up the buttons to modify the basemap.

setup_projection_menu()

Set up the menu to modify the basemap.

toggle_datagrid()

Toggle the visibility of the grid cell boundaries.

transform(x, y)

Transform coordinates of a point to the plots projection.

valid_variables(ds)

Get a list of variables that can be visualized with this plotmethod.

Attributes:

coord_combos

Get the combo boxes for x- and y-dimension and -coordinates.

fmt_setup_functions

Get a list of rows for formatoptions.

plotmethod

sp

Get the subproject of this plotmethod interface.

block_combos() Iterator[None][source]

Temporarilly block any signal of the coord_combos.

choose_next_projection() None[source]

Choose the next projection from the rcParams projection value.

property coord_combos: List[QComboBox]

Get the combo boxes for x- and y-dimension and -coordinates.

edit_basemap_settings() None[source]

Open a dialog to edit the basemap and projection settings.

edit_color_settings() None[source]

Open the dialog to edit the color settings.

edit_labels() None[source]

Open the dialog to edit the text labels in the plot.

fix_data()[source]

Call the fix_lonlatbox method of all map plotters.

fix_extent()[source]

Call the fix_map_extent method of all map plotters.

property fmt_setup_functions: List[Callable]

Get a list of rows for formatoptions.

This property returns a list of callable. Each callable should setup a horizonal (or widget) that is added to the layout vbox.

get_fmts(var: DataArray, init: bool = False) Dict[Hashable | str | Any, Any][source]

Get the formatoptions for a new plot.

Parameters:
  • var (xarray.Variable) – The variable in the base dataset

  • init (bool) – If True, call the init_dims() method to inject necessary formatoptions and dimensions for the initialization.

Returns:

A mapping from formatoption or dimension to the corresponding value for the plotmethod.

Return type:

dict

get_projection_label(proj: str) str[source]

Get the label for a projection in the GUI.

Parameters:

proj (str) – The projection value for the plot formatoption

Returns:

The label of the projection in the GUI

Return type:

str

get_projection_value(label: str) str[source]

Get the value for the projection formatoption.

This method is the inverse of get_projection_label().

Parameters:

label (str) – The projection label that is used in the GUI plot formatoption

Returns:

The value to use for the projection formatoption

Return type:

str

get_rows(func: Callable) List[List[GridCell]][source]

Get the rows of the formatoption widgets.

This method should take callable from the fmt_setup_functions list and return the rows corresponding to formatoption_rows.

get_slice(x: float, y: float) Dict[Hashable, int | slice] | None[source]

Get the slice for the selected coordinates.

This method is called when the user clicks on the coordinates in the plot.

Notes

This is reimplemented in the MapPlotWidget.

init_dims(var: DataArray) Dict[Hashable | str | Any, Any][source]

Get the formatoptions for a new plot.

This method updates the coordinates combo boxes with the x- and y-coordinate of the variable.

Parameters:

var (xarray.Variable) – The variable in the base dataset

Returns:

A mapping from formatoption or dimension to the corresponding value for the plotmethod.

Return type:

dict

open_cmap_dialog(N: int = 10) None[source]

Open the dialog to change the colormap.

Parameters:

N (int) – The number of colormaps to show

plotmethod: ClassVar[str] = 'mapplot'
refresh(ds: Dataset | None) None[source]

Refresh this widget from the given dataset.

refresh_from_sp() None[source]

Refresh this widget from the plotters project.

reset_extent_and_lonlatbox()[source]

Reset the extent and the lonlatbox to the defaults.

setEnabled(b: bool) None[source]

Enable or disable the projection and color buttons.

Parameters:

b (bool) – If True, enable the buttons, else disable.

set_cmap(cmap: str) None[source]

Update the plotter with the given colormap.

Parameters:

cmap (str) – The colormap name.

set_combo_text(combo: QComboBox, text: str) None[source]

Convenience function to update set the current text of a combobox.

Parameters:
  • combo (PyQt5.QtWidgets.QComboBox) – The combobox to modify

  • text (str) – The item to use

set_plot_type(plot_type: PlotType | None) None[source]

Update the value for the plot formatoption

Parameters:

ploy_type (PlotType or None) – The value for the plot formatoption.

set_projection(proj: str) None[source]

Update the projection of the plot with the given projection.

Parameters:

projection (str) – The projection name for the projection formatoption.

set_xcoord(text: str) None[source]

Set the name of the x-coordinate.

set_ycoord(text: str) None[source]

Set the name of the y-coordinate.

setup_cmap_menu() QMenu[source]

Set up the menu to change the colormaps.

setup_color_buttons() None[source]

Set up the buttons to change the colormap, etc.

setup_dimension_box() None[source]

Set up a box to control, what is the x and y-dimension.

setup_fix_extent_buttons()[source]

Setup the buttons for fixing the extent or data

setup_labels_button() None[source]

Add a button to modify the text labels.

setup_plot_buttons() None[source]

Setup the second row of formatoption widgets.

setup_projection_buttons() None[source]

Set up the buttons to modify the basemap.

setup_projection_menu() QMenu[source]

Set up the menu to modify the basemap.

property sp: Project | None

Get the subproject of this plotmethod interface.

toggle_datagrid() None[source]

Toggle the visibility of the grid cell boundaries.

transform(x: float, y: float) Tuple[float, float][source]

Transform coordinates of a point to the plots projection.

Parameters:
  • x (float) – The x-coordinate in axes coordinates

  • y (float) – The y-coordinate in axes coordinates

Returns:

  • float – The transformed x-coordinate x

  • float – The transformed y-coordinate y

valid_variables(ds: Dataset) List[Hashable][source]

Get a list of variables that can be visualized with this plotmethod.

Parameters:

ds (xarray.Dataset) – The dataset to use

Returns:

List of variable names to plot

Return type:

list of str

class psy_view.plotmethods.Plot2DWidget(get_sp: Callable[[], Project | None], ds: Dataset | None)[source]

Bases: MapPlotWidget

A widget to control the plot2d plotmethod.

Methods:

edit_labels()

Open the dialog to edit the text labels in the plot.

refresh_from_sp()

Refresh this widget from the plotters project.

setEnabled(b)

Enable or disable the datagrid and color buttons.

transform(x, y)

Reimplemented to not transform the coordinates.

Attributes:

fmt_setup_functions

Get a list of rows for formatoptions.

plotmethod

edit_labels() None[source]

Open the dialog to edit the text labels in the plot.

property fmt_setup_functions: List[Callable]

Get a list of rows for formatoptions.

This property returns a list of callable. Each callable should setup a horizonal (or widget) that is added to the layout vbox.

plotmethod: ClassVar[str] = 'plot2d'
refresh_from_sp() None[source]

Refresh this widget from the plotters project.

setEnabled(b: bool) None[source]

Enable or disable the datagrid and color buttons.

Parameters:

b (bool) – If True, enable the buttons, else disable.

transform(x: float, y: float) Tuple[float, float][source]

Reimplemented to not transform the coordinates.

class psy_view.plotmethods.PlotMethodWidget(get_sp: Callable[[], Project | None], ds: Dataset | None)[source]

Bases: QWidget

Base class for interfacing a psyplot plotmethod.

This method serves as a base class for interfacing any of the psyplot plot methods registered via psyplot.project.register_plotter().

The name of the plotmethod should be implemented as the plotmethod attribute.

Attributes:

array_info

changed(*args, **kwargs)

signalize that the widget has been changed but not plot changes are needed

data

Get the data of this plotmethod interface.

fmt_setup_functions

Get a list of rows for formatoptions.

formatoption_rows

Get a mapping from row name to a row of GridCells.

formatoptions

Get the formatoption keys of this plotmethod.

layout

plotmethod

plotter

Get the first plotter of the sp project.

replot(*args, **kwargs)

trigger a replot of this widget.

reset(*args, **kwargs)

trigger a replot of this widget.

sp

Get the subproject of this plotmethod interface.

Methods:

get_fmts(var[, init])

Get the formatoptions for a new plot.

get_rows(func)

Get the rows of the formatoption widgets.

get_slice(x, y)

Get the slice for the selected coordinates.

init_dims(var)

Get the formatoptions for a new plot.

refresh(ds)

Refresh this widget from the given dataset.

setup()

Set up the widget during initialization.

setup_separation_line()

Just a convenience function to create a separation line.

setup_widget_grid()

Setup the widget grid based on formatoption_rows.

setup_widgets()

Set up the widgets for this plotmethod.

trigger_refresh()

Emit the changed signal to notify changes in the plot.

trigger_replot()

Emit the replot signal to replot the project.

trigger_reset()

Emit the reset signal to reinitialize the project.

valid_variables(ds)

Get a list of variables that can be visualized with this plotmethod.

array_info = None
changed(*args, **kwargs)

signalize that the widget has been changed but not plot changes are needed

property data: DataArray | InteractiveList

Get the data of this plotmethod interface.

property fmt_setup_functions: List[Callable]

Get a list of rows for formatoptions.

This property returns a list of callable. Each callable should setup a horizonal (or widget) that is added to the layout vbox.

property formatoption_rows: List[List[GridCell]]

Get a mapping from row name to a row of GridCells.

property formatoptions: List[str]

Get the formatoption keys of this plotmethod.

get_fmts(var: DataArray, init: bool = False) Dict[Hashable | str | Any, Any][source]

Get the formatoptions for a new plot.

Parameters:
  • var (xarray.Variable) – The variable in the base dataset

  • init (bool) – If True, call the init_dims() method to inject necessary formatoptions and dimensions for the initialization.

Returns:

A mapping from formatoption or dimension to the corresponding value for the plotmethod.

Return type:

dict

get_rows(func: Callable) List[List[GridCell]][source]

Get the rows of the formatoption widgets.

This method should take callable from the fmt_setup_functions list and return the rows corresponding to formatoption_rows.

get_slice(x: float, y: float) Dict[Hashable, int | slice] | None[source]

Get the slice for the selected coordinates.

This method is called when the user clicks on the coordinates in the plot.

Notes

This is reimplemented in the MapPlotWidget.

init_dims(var: DataArray) Dict[Hashable | str | Any, Any][source]

Get the formatoptions for a new plot.

Parameters:

var (xarray.Variable) – The variable in the base dataset

Returns:

A mapping from formatoption or dimension to the corresponding value for the plotmethod.

Return type:

dict

layout: QGridLayout = None
plotmethod: ClassVar[str] = ''
property plotter: Plotter | None

Get the first plotter of the sp project.

refresh(ds: Dataset | None) None[source]

Refresh this widget from the given dataset.

replot(*args, **kwargs)

trigger a replot of this widget. This can be emitted with the trigger_replot() method

reset(*args, **kwargs)

trigger a replot of this widget. This can be emitted with the trigger_reset() method

setup() None[source]

Set up the widget during initialization.

setup_separation_line() None[source]

Just a convenience function to create a separation line.

This method does nothing but tells get_rows() to add an instance of QHline.

setup_widget_grid() None[source]

Setup the widget grid based on formatoption_rows.

setup_widgets() None[source]

Set up the widgets for this plotmethod.

property sp: Project | None

Get the subproject of this plotmethod interface.

trigger_refresh()[source]

Emit the changed signal to notify changes in the plot.

trigger_replot() None[source]

Emit the replot signal to replot the project.

trigger_reset()[source]

Emit the reset signal to reinitialize the project.

valid_variables(ds: Dataset) List[Hashable][source]

Get a list of variables that can be visualized with this plotmethod.

Parameters:

ds (xarray.Dataset) – The dataset to use

Returns:

List of variable names to plot

Return type:

list of str

class psy_view.plotmethods.PlotType(value)[source]

Bases: str, Enum

A value for the 2D plot formatoption.

Attributes:

contour

contourf

mesh

poly

contour = 'contour'
contourf = 'contourf'
mesh = 'mesh'
poly = 'poly'
class psy_view.plotmethods.QHLine[source]

Bases: QFrame

A horizontal seperation line.

psy_view.plotmethods.projection_map = {'cf': 'Default', 'cyl': 'Cylindric', 'moll': 'Mollweide', 'northpole': 'Arctic (Northpole)', 'ortho': 'Orthographic', 'robin': 'Robinson', 'southpole': 'Antarctic (Southpole)'}

A mapping from projection identifier to the text we want to use in the GUI