solarwindpy.Hist2Dο
- class Hist2D(x, y, z=None, axnorm=None, logx=False, logy=False, clip_data=False, nbins=101, bin_precision=None)[source]ο
Bases:
PlotWithZdata,CbarMaker,AggPlotCreate a 2D histogram with an optional z-value using an equal number.
of bins along the x and y axis.
- Parameters:
x (pd.Series) β x and y data to aggregate
y (pd.Series) β x and y data to aggregate
z (None, pd.Series) β If not None, the z-value to aggregate.
axnorm (str) β
- Normalize the histogram.
key normalization β ββββ- c column r row t total d density
logx (bool) β If True, log10 scale the axis.
logy (bool) β If True, log10 scale the axis.
- dataο
- binsο
- cutο
- axnormο
- log<x,y>
- <x,y,z>label
- pathο
- Type:
None, Path
- calc_bins:
calculate the x, y bins.
- make_cut:
Utilize the calculated bins to convert (x, y) into pd.Categoral or pd.Interval values used in aggregation.
- set_[x,y,z]label:
Set the x, y, or z label.
- agg:
Aggregate the data in the bins. If z-value is None, count the number of points in each bin. If z-value is not None, calculate the mean for each bin.
- make_plot:
Make a 2D plot of the data with an optional color bar.
- __init__(x, y, z=None, axnorm=None, logx=False, logy=False, clip_data=False, nbins=101, bin_precision=None)[source]ο
- set_labels(**kwargs)[source]ο
Set or update x, y, or z labels. Any label not specified in kwargs.
is propagated from self.labels.<x, y, or z>.
- set_axnorm(new)[source]ο
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
- agg(**kwargs)[source]ο
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.
- make_plot(ax=None, cbar=True, limit_color_norm=False, cbar_kwargs=None, fcn=None, alpha_fcn=None, **kwargs)[source]ο
Make a 2D plot on ax using ax.pcolormesh.
- 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 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().alpha_fcn (None, str) β If not None, the function used to aggregate the data for setting alpha value.
kwargs β Passed to ax.pcolormesh. If row or column normalized data, norm defaults to mpl.colors.Normalize(0, 1).
- Returns:
ax (mpl.axes.Axes) β Axes upon which plot was made.
cbar_or_mappable (colorbar.Colorbar, mpl.collections.QuadMesh) β If cbar is True, return the colorbar. Otherwise, return the Quadmesh used to create the colorbar.
- 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)[source]ο
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.
- get_border()[source]ο
Get the top and bottom edges of the plot.
- Returns:
border β Contains βtopβ and βbottomβ fields, each with a
pd.Series.- Return type:
namedtuple
- plot_edges(ax, smooth=True, sg_kwargs=None, **kwargs)[source]ο
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_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)[source]ο
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).
- project_1d(axis, only_plotted=True, project_counts=False, **kwargs)[source]ο
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:
- id_data_above_contour(level)[source]ο
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
- take_data_in_yrange_across_x(ranges_by_x, get_x_bounds, get_y_bounds)[source]ο
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
- 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_plotted_data_boolean_series()ο
Return a boolean
pd.Seriesidentifying 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.
- 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.
- property pathο
Path for saving figure.
- 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_clim(lower=None, upper=None)ο
Set the minimum (lower) and maximum (upper) allowed number of.
counts per bin to return after calling
agg().
- set_log(x=None, y=None)ο
- set_path(new, add_scale=True)ο
Build the plot save path.