XarrayContourPlotElement
- class PlasmaCalcs.plotting.contours.XarrayContourPlotElement(array, *, ax=None, contourf=False, **kw_super)
Bases:
MoviePlotElementplot 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.contourf: bool (default: False)whether to use filled contours (i.e., plt.contourf) or not (i.e., plt.contour).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__.
colorbar(*[, colorbar_linewidth, ...])add a colorbar to the plot.
initialize the contour plot; actually plot the data.
legend_handle([label])return a handle to be used in a legend for this plot.
update_data(data)update the plot using data['array'].
_contour_plotter(array)return plotter to use for making contours.
return kwargs to use for making contours.
Attributes
array for plot.
the axes containing this contour plot
contour plot (instance of matplotlib.contour.QuadContourSet)
figure containing this contour plot
alias to legend_handle
- 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.
- _contour_plotter(array)
return plotter to use for making contours.
array.plot.contourf or array.plot.contour, depending on self.plot_settings[‘contourf’].
- _contour_plotter_kwargs()
return kwargs to use for making contours.
array.plot.contourf or array.plot.contour, depending on self.plot_settings[‘contourf’].
- 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.