Plotmethod widgets.
This module defines the widgets to interface with the mapplot, plot2d and lineplot plotmethods.
Classes:
|
A grid cell within a QGridLayout managing one QWidget. |
|
A widget to control the lineplot plotmethod. |
|
A widget to control the mapplot plotmethod. |
|
A widget to control the plot2d plotmethod. |
|
Base class for interfacing a psyplot plotmethod. |
|
A value for the 2D |
|
A horizontal seperation line. |
Data:
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:
The number of columns to cover
The starting column for the widget.
the
PyQt5.QtWidgets.QWidget
instance (i.e. the widget) or a layout (PyQt5.QtWidgets.QLayout
).A boolean whether to add stretch or not
Methods:
from_alias
(o[, c, cs, s])Create a
GridCell
from shorter kws.- 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.
- qobject: QWidget | QLayout
the
PyQt5.QtWidgets.QWidget
instance (i.e. the widget) or a layout (PyQt5.QtWidgets.QLayout
)
- 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.
Temporarilly block any signal of the combo boxes.
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 the current line from the plot.
setEnabled
(b)Enable or disable the datagrid and color buttons.
Set up the combobox for selecting the x-dimension.
Add a button to modify the text labels.
Setup the row for selecting new lines.
valid_variables
(ds)Get a list of variables that can be visualized with this plotmethod.
Attributes:
The first array in the list.
Get a list of rows for formatoptions.
Get the labels for the individual lines.
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.
- property data: DataArray
The first array in the list.
- 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 toformatoption_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:
- setEnabled(b: bool) None [source]
Enable or disable the datagrid and color buttons.
- Parameters:
b (bool) – If True, enable the buttons, else disable.
- 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:
- class psy_view.plotmethods.MapPlotWidget(get_sp: Callable[[], Project | None], ds: Dataset | None)[source]
Bases:
PlotMethodWidget
A widget to control the mapplot plotmethod.
Methods:
Temporarilly block any signal of the
coord_combos
.Choose the next projection from the rcParams projection value.
Open a dialog to edit the basemap and projection settings.
Open the dialog to edit the color settings.
Open the dialog to edit the text labels in the plot.
fix_data
()Call the fix_lonlatbox method of all map plotters.
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 this widget from the plotters project.
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
formatoptionset_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.
Set up the menu to change the colormaps.
Set up the buttons to change the colormap, etc.
Set up a box to control, what is the x and y-dimension.
Setup the buttons for fixing the extent or data
Add a button to modify the text labels.
Setup the second row of formatoption widgets.
Set up the buttons to modify the basemap.
Set up the menu to modify the basemap.
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:
Get the combo boxes for x- and y-dimension and -coordinates.
Get a list of rows for formatoptions.
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.
- 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:
- get_projection_value(label: str) str [source]
Get the value for the projection formatoption.
This method is the inverse of
get_projection_label()
.
- 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 toformatoption_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:
- open_cmap_dialog(N: int = 10) None [source]
Open the dialog to change the colormap.
- Parameters:
N (int) – The number of colormaps to show
See also
- 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_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 up the menu to change the colormaps.
Set up the menu to modify the basemap.
- transform(x: float, y: float) Tuple[float, float] [source]
Transform coordinates of a point to the plots projection.
- 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:
- class psy_view.plotmethods.Plot2DWidget(get_sp: Callable[[], Project | None], ds: Dataset | None)[source]
Bases:
MapPlotWidget
A widget to control the plot2d plotmethod.
Methods:
Open the dialog to edit the text labels in the plot.
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:
Get a list of rows for formatoptions.
- 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.
- 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:
changed
(*args, **kwargs)signalize that the widget has been changed but not plot changes are needed
Get the data of this plotmethod interface.
Get a list of rows for formatoptions.
Get a mapping from row name to a row of
GridCells
.Get the formatoption keys of this plotmethod.
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.
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.
Just a convenience function to create a separation line.
Setup the widget grid based on
formatoption_rows
.Set up the widgets for this plotmethod.
Emit the
changed
signal to notify changes in the plot.Emit the
replot
signal to replot the project.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
.
- 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:
- 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 toformatoption_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:
- layout: QGridLayout = None
- 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_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 ofQHline
.
- setup_widget_grid() None [source]
Setup the widget grid based on
formatoption_rows
.
- 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:
- class psy_view.plotmethods.PlotType(value)[source]
-
A value for the 2D
plot
formatoption.Attributes:
- contour = 'contour'
- contourf = 'contourf'
- mesh = 'mesh'
- poly = 'poly'
- 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