PlasmaCalcs.plotting.contours.XarrayContourPlotElement

class PlasmaCalcs.plotting.contours.XarrayContourPlotElement(array, *, ax=None, **kw_super)

Bases: MoviePlotElement

plot contours of 2D data.
array: xarray.DataArray, probably ndim=2.
the data to be plotted.
add_colorbar: UNSET or bool (default: UNSET)
if provided, default for add_colorbar when making xarray plots.
colorbar_linewidth: UNSET, None, int, list-like, or 2-tuple of None/int. (default: UNSET)
linewidth for lines in contour colorbar.
UNSET –> use DEFAULTS.PLOT.COLORBAR_LINEWIDTH (default: (4, None)).
None –> use same width as contour lines.
int or list-like –> use this as the linewidth
(as per matplotlib.collections.LineCollection.set(linewidth=…))
tuple –> defines (min, max) linewidths; use None for no bound.
E.g. (4, None) says “for thinner lines use 4; others same as contour lines”.
colorbar_linestyle: UNSET, None, or str (default: UNSET)
linestyle for lines in contour colorbar.
UNSET –> use DEFAULTS.PLOT.COLORBAR_LINESTYLE (default: None).
None –> use same style as contour lines.
colorbar_lines_set: UNSET, or dict (default: UNSET)
any additional attrs to set for contour colorbar lines,
via cbar.ax.get_children()[1].set(…)
label: UNSET or str (default: UNSET)
label for this plot element, to be included in a legend.
For xarrays, will label.format(**xarray_nondim_coords(array)).
UNSET –> no label.
legend_handle_kw: UNSET or dict (default: UNSET)
any additional kwargs to use when creating legend handles.
To view or adjust plot settings in self, see self.plot_settings, or help(self.plot_settings).
__init__(array, *, ax=None, **kw_super)

Methods

__init__(array, *[, ax])

colorbar(*[, colorbar_linewidth, ...])

init_contour()

legend_handle([label])

update_data(data)

Attributes

array

ax

contour

fig

handle

property array
array for plot. Internally, stored at self.data[‘array’]
property ax
the axes containing this contour plot
colorbar(*, colorbar_linewidth=UNSET, colorbar_linestyle=UNSET, colorbar_lines_set=UNSET, **kw_plt_colorbar)
add a colorbar to the plot. sets self.cbar = Colorbar object, and returns it.
property contour
contour plot (instance of matplotlib.contour.QuadContourSet)
property fig
figure containing this contour plot
property handle
alias to legend_handle
init_contour()
initialize the contour plot; actually plot the data.
stores plotted object in self.contour and returns self.contour.
legend_handle(label=UNSET, **kw_line_2D_set)
return a handle to be used in a legend for this plot.
Will look like the first contour line in self.contour,
but then apply any settings from kw_line_2D_set.
E.g. provide color=’black’ to make a line like the first contour, but black.
Recommend:
plt.legend(handles=[self.legend_handle(), …])
filling in the … with any other artists who have legend elements to draw.
To grab the default list of handles, you can use:
default_handles = ax.get_legend_handles_labels()[0].
where ax is the axis where objects are plotted (maybe self.ax, or plt.gca()).
Putting these together would result in something like:
plt.legend(handles=[self.legend_handle(), *default_handles], …)
If the handles aren’t long enough to visually distinguish, try handlelength=5 or more.
update_data(data)
update the plot using data[‘array’].
return the list of all updated matplotlib Artist objects.