PatchPlotElement

class PlasmaCalcs.plotting.patches.PatchPlotElement(params, *, ax=None, transform=UNSET, **kw_super)

Bases: MoviePlotElement

plot a 2D Patch.

Base class for useable 2D patch plot elements, e.g. XarrayRectanglePatchPlotElement.
params: dict
dict of patch-related parameters.
Many are probably settable directly via patch.set(**params).
E.g. ‘width’ and ‘height’ are options for rectangle patch.
transform: UNSET, ‘data’, ‘axes’, 2-tuple of (‘data’ or ‘axes’), or Transform object (default: UNSET)
indicate coordinate system to use for x and y inputs.
single string –> x and y both in this coordinate system.
tuple –> xy[0] tells x system; xy[1] tells y system.
‘data’ coords means input values match data values.
‘axes’ coords means input values correspond to distance across axis:
for x: left=0, right=1.
for y: bottom=0, top=1.
cls.MPL_SETTERS: dict of {param key: how to set that param}
for params with nonstandard setters in matplotlib, tells the alternative to patch.set(k=value):
{str k: str v} –> patch.set(v=value)
{str k: (str attr, str v)} –> patch.attr(v=value)
Examples:
- for Annulus patch, need MPL_SETTERS[‘r’] = ‘radii’,
because patch.set(r=value) isn’t allowed; it’s patch.set(radii=value) instead.
- for Arrow patch, need MPL_SETTERS[‘x’] = (‘set_data’, ‘x’),
because patch.set(x=value) isn’t allowed; it’s patch.set_data(x=value) instead.
To view or adjust plot settings in self, see self.plot_settings, or help(self.plot_settings).

Methods

__init_subclass__(*args_super, **kw)

appends note about using self.plot_settings, to cls.__doc__.

init_patch()

initialize the patch; actually draw the patch on self.ax.

legend_handle(*[, hatch_density_scaling, label])

returns a Patch suitable for use as a handle in a legend.

update_data(data)

updating the plot using data['params'].

_all_patch_params(ax)

returns full list of all known patch params to use, i.e.:

_params_to_patch_init_kwargs(params)

returns kwargs to use for initializing the patch, based on these params.

_params_to_patch_update_kwargs(params)

returns kwargs to use for updating the patch, based on these params.

_set_patch_params(**params)

update the parameters of self.patch.

_transform_kw(ax)

get transform to use for this patch, as dict.

Attributes

MPL_SETTERS

PATCH_SETTINGS_LOOKUP

ax

the axes containing this patch

fig

the figure containing this patch

params

dict of patch parameters.

patch

the matplotlib.patches.Patch object

patch_cls

classmethod __init_subclass__(*args_super, **kw)

appends note about using self.plot_settings, to cls.__doc__.

if “PlotSettings” or “plot_settings” appears in cls.__doc__, do NOT append this note;
assuming instead that this means the doc already mentions how to use plot_settings.
_all_patch_params(ax)

returns full list of all known patch params to use, i.e.:

{**params_settings, **params_init}, where:
params_settings = self.plot_settings.get_mpl_kwargs(self.PATCH_SETTINGS_LOOKUP)
params_init = self._params_to_patch_init_kwargs()
_params_to_patch_init_kwargs(params)

returns kwargs to use for initializing the patch, based on these params.

The implementation here just returns params, unchanged.
Subclass might override (e.g. RectanglePatchPlotElement join ‘x0’ and ‘y0’ into ‘xy’).
The result should be a dict of kwargs suitable for self.patch_cls.__init__.
_params_to_patch_update_kwargs(params)

returns kwargs to use for updating the patch, based on these params.

The implementation here just returns params, unchanged.
Subclass might override (e.g. RectanglePatchPlotElement rename ‘x0’ to ‘x’ and ‘y0’ to ‘y’).
The result should be a dict of kwargs suitable for self._set_patch_params
(i.e., before applying logic due to MPL_SETTERS).
_set_patch_params(**params)

update the parameters of self.patch.

params: dict
dict of patch parameters.
All must be provideable during (type of patch).__init__.
Many are probably settable directly via patch.set(**params).
E.g. ‘width’ and ‘height’ are options for rectangle patch.
Some might not be settable directly; see self.MPL_SETTERS and help(self) for details.
_transform_kw(ax)

get transform to use for this patch, as dict.

result is probably dict(transform=Transform object), but might be empty dict().
requires that self.ax is not None.
property ax

the axes containing this patch

property fig

the figure containing this patch

init_patch()

initialize the patch; actually draw the patch on self.ax.

stores plotted object in self.patch and returns self.patch.
legend_handle(*, hatch_density_scaling=2, label=UNSET)

returns a Patch suitable for use as a handle in a legend.

hatch_density_scaling: int
increase the hatch density by this factor, relative to the plot itself, if using hatches.
label: UNSET or str
if not UNSET, use this as the label, instead of self.plot_settings[‘label’]
Example:
handle1 = self.legend_handle()
handle2 = other_patch_element.legend_handle()
plt.legend(handles=[handle1, handle2])
property params

dict of patch parameters. Internally, stored at self.data[‘params’]

property patch

the matplotlib.patches.Patch object

update_data(data)

updating the plot using data[‘params’].

return the list of all updated matplotlib Artist objects (i.e., [self.patch])