solarwindpy.instabilities.beta_ani.BetaRPlot

class BetaRPlot(beta, ani, species, **kwargs)[source]

Bases: Hist2D

Generate a beta–anisotropy histogram.

Parameters:
  • beta (pandas.Series) – Proton parallel beta.

  • ani (pandas.Series) – Temperature anisotropy.

  • species (str) – Label used to generate axis titles.

  • **kwargs – Additional options forwarded to Hist2D. By default the x- and y-axes use logarithmic scaling.

Examples

>>> br = BetaRPlot(beta, ani, "p")
>>> ax, cbar = br.make_plot()
__init__(beta, ani, species, **kwargs)[source]

Instantiate the histogram plot.

Parameters:
  • beta (pandas.Series) – Proton parallel beta.

  • ani (pandas.Series) – Temperature anisotropy.

  • species (str) – Label used to generate axis titles.

  • **kwargs – Additional options forwarded to Hist2D.

make_plot(**kwargs)[source]

Plot the histogram.

Parameters:

**kwargs – Additional options forwarded to Hist2D.make_plot.

Returns:

  • matplotlib.axes.Axes – Axis containing the plot.

  • matplotlib.colorbar.Colorbar – Colorbar associated with the plot.

agg(**kwargs)

Perform the aggregation along the agg axes.

If either of the count limits specified in clim are not None, apply them.

fcn allows you to specify a specific function for aggregation. Otherwise, automatically choose β€œcount” or β€œmean” based on the uniqueness of the aggregated values.

property agg_axes

The axis to aggregate into, e.g. the z variable in an (x, y, z) heatmap.

property alim
property axnorm

Data normalization in plot.

Not mpl.colors.Normalize instance. That is passed as a kwarg to make_plot.

calc_bins_intervals(nbins=101, precision=None)

Calculate histogram bins.

nbins: int, str, array-like

If int, use np.histogram to calculate the bin edges. If str and nbins == β€œknuth”, use astropy.stats.knuth_bin_width to calculate optimal bin widths. If str and nbins != β€œknuth”, use np.histogram(data, bins=nbins) to calculate bins. If array-like, treat as bins.

precision: int or None

Precision at which to store intervals. If None, default to 3.

property categoricals
property clim
property clip
static clip_data(data, clip)
property cut
property data
property edges
get_border()

Get the top and bottom edges of the plot.

Returns:

border – Contains β€œtop” and β€œbottom” fields, each with a pd.Series.

Return type:

namedtuple

get_plotted_data_boolean_series()

Return a boolean pd.Series identifying each plotted measurement.

The series shares the same index as the stored data. To align with a different index you may need to adjust the returned series.

get_subset_above_threshold(threshold, fcn='count')

Get the subset of data above a given threshold using fcn to.

aggregate. If axnorm set, this is used.

property grouped

joint.groupby with appropriate axes passes.

id_data_above_contour(level)

Gets data above the level.

Parameters:

level (scalar) – The z-value above which to select data. Data is aggregated according to ax_norm.

Returns:

above_contour – For data in a bin above level, indicates the x-pd.Interval within which the observation falls. NaN are observations that are below level. This object is purposely the same length as the data stored by Hist2D and can be used in groupby operations.

Return type:

pd.Series

property intervals
property joint

Combines the categorical and continuous data for Groupby.

property labels
property log
property logger
make_cut()

Calculate the Categorical quantities for the aggregation axes.

make_joint_h2_h1_plot(project_counts=True, kwargs_1d=None, fig_axes=None, **kwargs)
property path

Path for saving figure.

plot_contours(ax=None, label_levels=True, cbar=True, limit_color_norm=False, cbar_kwargs=None, fcn=None, plot_edges=False, edges_kwargs=None, clabel_kwargs=None, skip_max_clbl=True, use_contourf=False, gaussian_filter_std=0, gaussian_filter_kwargs=None, nan_aware_filter=False, **kwargs)

Make a contour plot on ax using ax.contour.

Parameters:
  • ax (mpl.axes.Axes, None) – If None, create an Axes instance from plt.subplots.

  • label_levels (bool) – If True, add labels to contours with ax.clabel.

  • cbar (bool) – If True, create color bar with labels.z.

  • limit_color_norm (bool) – If True, limit the color range to 0.001 and 0.999 percentile range of the z-value, count or otherwise.

  • cbar_kwargs (dict, None) – If not None, kwargs passed to self._make_cbar.

  • fcn (FunctionType, None) – Aggregation function. If None, automatically select in agg().

  • plot_edges (bool) – If True, plot the smoothed, extreme edges of the 2D histogram.

  • edges_kwargs (None, dict) – Passed to {self.plot_edges!s}.

  • clabel_kwargs (None, dict) – If not None, dictionary of kwargs passed to ax.clabel.

  • skip_max_clbl (bool) – If True, don’t label the maximum contour. Primarily used when the maximum contour is, effectively, a point.

  • maximum_color – The color for the maximum of the PDF.

  • use_contourf (bool) – If True, use ax.contourf. Else use ax.contour.

  • gaussian_filter_std (int) – If > 0, apply scipy.ndimage.gaussian_filter to the z-values using the standard deviation specified by gaussian_filter_std.

  • gaussian_filter_kwargs (None, dict) – If not None and gaussian_filter_std > 0, passed to scipy.ndimage.gaussian_filter()

  • nan_aware_filter (bool) – If True and gaussian_filter_std > 0, use NaN-aware filtering via normalized convolution. Otherwise use standard scipy.ndimage.gaussian_filter.

  • kwargs – Passed to ax.pcolormesh(). If row or column normalized data, norm defaults to mpl.colors.Normalize(0, 1).

plot_edges(ax, smooth=True, sg_kwargs=None, **kwargs)

Overplot the edges.

Parameters:
  • ax – Axis on which to plot.

  • smooth (bool) – If True, apply a Savitzky-Golay filter (scipy.signal.savgol_filter()) to the y-values before plotting to smooth the curve.

  • sg_kwargs (dict, None) – If not None, dict of kwargs passed to Savitzky-Golay filter. Also allows for setting of window_length and polyorder as kwargs. They default to 10% of the number of observations (window_length) and 3 (polyorder). Note that because window_length must be odd, if the 10% value is even, we take 1-window_length.

  • kwargs – Passed to ax.plot

plot_hist_with_contours(ax=None, cbar=True, limit_color_norm=False, cbar_kwargs=None, fcn=None, levels=None, label_levels=False, use_contourf=True, contour_kwargs=None, clabel_kwargs=None, skip_max_clbl=True, gaussian_filter_std=0, gaussian_filter_kwargs=None, nan_aware_filter=False, **kwargs)

Make a 2D pcolormesh plot with contour overlay.

Combines make_plot (pcolormesh background) with plot_contours (contour/contourf overlay) in a single call.

Parameters:
  • ax (mpl.axes.Axes, None) – If None, create an Axes instance from plt.subplots.

  • cbar (bool) – If True, create color bar with labels.z.

  • limit_color_norm (bool) – If True, limit the color range to 0.001 and 0.999 percentile range.

  • cbar_kwargs (dict, None) – If not None, kwargs passed to self._make_cbar.

  • fcn (FunctionType, None) – Aggregation function. If None, automatically select.

  • levels (array-like, int, None) – Contour levels. If None, automatically determined.

  • label_levels (bool) – If True, add labels to contours with ax.clabel.

  • use_contourf (bool) – If True, use filled contours. Else use line contours.

  • contour_kwargs (dict, None) – Additional kwargs passed to contour/contourf (e.g., linestyles, colors).

  • clabel_kwargs (dict, None) – Kwargs passed to ax.clabel.

  • skip_max_clbl (bool) – If True, don’t label the maximum contour level.

  • gaussian_filter_std (int) – If > 0, apply Gaussian filter to contour data.

  • gaussian_filter_kwargs (dict, None) – Kwargs passed to scipy.ndimage.gaussian_filter.

  • nan_aware_filter (bool) – If True and gaussian_filter_std > 0, use NaN-aware filtering via normalized convolution. Otherwise use standard scipy.ndimage.gaussian_filter.

  • kwargs – Passed to ax.pcolormesh.

Returns:

  • ax (mpl.axes.Axes)

  • cbar_or_mappable (colorbar.Colorbar or QuadMesh)

  • qset (QuadContourSet) – The contour set from the overlay.

  • lbls (list or None) – Contour labels if label_levels is True.

project_1d(axis, only_plotted=True, project_counts=False, **kwargs)

Make a Hist1D from the data stored in this His2D.

Parameters:
  • axis (str) – β€œx” or β€œy”, specifying the axis to project into 1D.

  • only_plotted (bool) – If True, only pass data that appears in the {self.__class__.__name__} plot to the Hist1D.

  • project_counts (bool) – If True, only send the variable plotted along axis to Hist1D. Otherwise, send both axes (but not z-values).

  • kwargs – Passed to Hist1D. Primarily to allow specifying bin_precision.

Returns:

h1

Return type:

Hist1D

set_alim(lower=None, upper=None)

Set the minimum (lower) and maximum (upper) allowed value when.

aggregating. This is different from clim because it uses the agg_fcn. So behavior will change based on axnorm, etc.

set_axnorm(new)

The method by which the gridded data is normalized.

key

description

c

Column normalize

d

Density normalize

r

Row normalize

t

Total normalize

cd

PDFs in each column

rd

PDFs in each row

set_clim(lower=None, upper=None)

Set the minimum (lower) and maximum (upper) allowed number of.

counts per bin to return after calling agg().

set_data(x, y, z, clip)
set_labels(**kwargs)

Set or update x, y, or z labels. Any label not specified in kwargs.

is propagated from self.labels.<x, y, or z>.

set_log(x=None, y=None)
set_path(new, add_scale=True)

Build the plot save path.

Parameters:
  • new (str or Path) – If str and == β€œauto”, then build path from self.labels. Otherwise, assume parameter specifies the desired path and use Path(new).

  • add_scale (bool) – If True, add information about the axis scales to the end of the path.

take_data_in_yrange_across_x(ranges_by_x, get_x_bounds, get_y_bounds)

Take data within y-ranges across x-values.

Parameters:
  • ranges_by_x (iterable) – An iterable with keys used to get the left and right bounds for the data and values used to get the top and bottom bounds for the data.

  • get_x_bounds (function) – First argument is one key of ranges_by_x and returns left, right. Second argument is a kwarg (expected_logx) boolean to transform the returned values according to whether or not the keys are \(log(x)\) or \(x\) in a manner that matches data stored in Hist2D.

  • get_y_bounds (functions) – Takes on value of ranges_by_x and returns top, bottom. Second argument Second argument is a kwarg (expected_logx) boolean to transform the returned values according to whether or not the keys are \(log(y)\) or \(y\) in a manner that matches data stored in Hist2D.

Returns:

taken – Array of indices for selecting data in interval.

Return type:

np.ndarray 1D