solarwindpy.Hist1D

class Hist1D(x, y=None, logx=False, axnorm=None, clip_data=False, nbins=101, bin_precision=None)[source]

Bases: AggPlot

Create 1D plot of x, optionally aggregating y in bins of x.

_gb_axes, path
set_path, set_data, agg, _format_axis, make_plot
__init__(x, y=None, logx=False, axnorm=None, clip_data=False, nbins=101, bin_precision=None)[source]

Create a one-dimensional histogram.

Parameters:
  • x (pandas.Series) – Data from which to create bins.

  • y (pandas.Series or None, optional) – Values to aggregate in bins of x. If None, counts of x are used.

  • logx (bool, optional) – If True, compute bins in logarithmic space.

  • axnorm ({"t", "d", None}, optional) – Normalisation applied to the histogram. "t" uses total counts and "d" yields a density.

  • clip_data (bool, optional) – Remove extreme values at the 0.001 and 0.999 percentiles before binning or aggregation.

  • nbins (int or array-like, optional) – Binning strategy passed to numpy.histogram_bin_edges() or pandas.cut() depending on the input type.

  • bin_precision (int, optional) – Precision for decimal bin edges.

set_path(new, add_scale=True)[source]

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.

set_data(x, y, clip)[source]
set_axnorm(new)[source]

The method by which the gridded data is normalized.

key

description

d

Density normalize

t

Total normalize

construct_cdf(only_plotted=True)[source]

Convert the obsered measuremets.

Returns:

cdf – β€œx” column is the value of the measuremnt. β€œposition” column is the normalized position in the cdf. To plot the cdf:

cdf.plot(x=”x”, y=”cdf”)

Return type:

pd.DataFrame

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.

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>.

make_plot(ax=None, fcn=None, transpose_axes=False, gaussian_filter_std=0, plot_window=False, plot_window_edges=False, gaussian_filter_kwargs=None, **kwargs)[source]

Make a plot.

Parameters:
  • ax (None, mpl.axis.Axis) – If None, create a subplot axis.

  • fcn (None, str, aggregative function, or 2-tuple) – Passed directly to {self.__class__.__name__}.agg. If None, use the default aggregation function. If str or a single aggregative function, use it. If a 2-tuple is passed, then the first element aggregates and the second element calculates an uncertainty.

  • transpose_axes (bool) – If True, plot independent values on y-axis and dependent values on x-axis. Primary use case is plotting 1D projection of 2D plot adjascent to 2D axis.

  • 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()

  • plot_window (bool) – Requires two functions passed to fcn. Instead of error bars, plots the uncertainty window as a semi-transparent band.

  • plot_window_edges (bool) – If True, plot solid lines at the window boundaries.

  • kwargs – Passed directly to ax.plot.

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.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.

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)