solarwindpy.fitfunctions.plots

Plotting utilities for solarwindpy.fitfunctions.

This module contains FFPlot, a helper for visualizing fitted models, residuals and associated annotations.

Classes

AxesLabels(x,Β y,Β z)

FFPlot(observations,Β y_fit,Β TeX_info,Β fit_result)

LogAxes(x,Β y)

class AxesLabels(x, y, z)

Bases: tuple

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=sys.maxsize, /)

Return first index of value.

Raises ValueError if the value is not present.

x

Alias for field number 0

y

Alias for field number 1

z

Alias for field number 2

class LogAxes(x, y)

Bases: tuple

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=sys.maxsize, /)

Return first index of value.

Raises ValueError if the value is not present.

x

Alias for field number 0

y

Alias for field number 1

class FFPlot(observations, y_fit, TeX_info, fit_result, fitfunction_name='')[source]

Bases: object

__init__(observations, y_fit, TeX_info, fit_result, fitfunction_name='')[source]

Container for plotting a FitFunction.

Parameters:
  • observations (Observations) – Observed data used in the fit.

  • y_fit (array-like) – Model evaluated at the observed x values.

  • TeX_info (TeXinfo) – Object describing the fit for annotation.

  • fit_result (scipy.optimize.OptimizeResult) – Result object returned from the fitting routine.

  • fitfunction_name (str, optional) – Name of the originating fit function.

property labels
property log
property observations
property fitfunction_name
property fit_result
property path
property TeX_info
property y_fit
set_fitfunction_name(new)[source]

Set the descriptive name for saved plots.

set_fit_result(new)[source]

Store the optimization result object.

set_observations(observations, y_fit)[source]

Set raw and fitted values used for plotting.

plot_raw(ax=None, plot_window=True, edge_kwargs=None, **kwargs)[source]

Plot the observations used in the fit from raw data.

Plot from self.observations.raw.x(), self.observations.raw.y(), self.observations.raw.w().

Parameters:

edge_kwargs (None, dict) – If not None, plot edges on the window using these kwargs.

plot_used(ax=None, plot_window=True, edge_kwargs=None, **kwargs)[source]

Plot the observations used in the fit from used data.

Plot from self.observations.used.x(), self.observations.used.y(), and self.observations.used.w().

plot_fit(ax=None, annotate=True, annotate_kwargs=None, **kwargs)[source]

Plot the fit.

plot_raw_used_fit(ax=None, drawstyle=None, annotate=True, raw_kwargs=None, used_kwargs=None, fit_kwargs=None, annotate_kwargs=None)[source]

Make a plot of the raw observations, observations in fit, and the fit.

Combines the outputs of self.plot_raw(), self.plot_used(), and self.plot_fit().

Parameters:
  • ax (None, mpl.Axes.axis_subplot)

  • drawstyle (str, None) – mpl drawstyle, shared by self.plot_raw() and self.plot_used(). If None, defaults to β€œsteps-mid”.

  • annotate (True) – If True, add fit info to the annotation using ax.text.

  • raw_kwargs (dict) – Passed to ax.plot(**kwargs) in self.plot_raw().

  • used_kwargs (dict) – Passed to ax.plot(**kwargs) in self.plot_used().

  • fit_kwargs (dict) – Passed to ax.plot(**fit_kwargs) for plotting fit.

  • annotate_kwargs – Passed to ax.text.

Returns:

ax

Return type:

mpl.Axes.axis_subplot

plot_residuals(ax=None, pct=True, subplots_kwargs=None, kind='both', **kwargs)[source]

Plot residuals for the data used in the fit.

Residuals are shown on a symlog scale with linthresh=10. By default they are expressed as percentages of the fitted model.

Parameters:
  • ax (mpl.axes.Axes, optional) – Axis to draw on. If None a new figure and axis are created.

  • pct (bool, default True) – If True, show residuals as percentages.

  • subplots_kwargs (dict, optional) – Passed to plt.subplots when ax is None.

  • kind ({'simple', 'robust', 'both'}, default "both") – Which residuals to plot.

  • **kwargs – Additional keyword arguments passed to ax.plot.

Returns:

ax – Axis with residuals plotted.

Return type:

mpl.axes.Axes

plot_raw_used_fit_resid(annotate=True, fit_resid_axes=None, figsize=(6, 4), resid_kwargs=None, **kwargs)[source]

Make a stacked fit, residual plot.

Parameters:
  • annotate (bool) – If True, add fit annotation to axis.

  • fit_resid_axes (None, 2-tuple of mpl.axis.Axis) – If not None, (fit, resid) axis pair to plot the (raw, used, fit) and residual on, respectively. Otherwise, use GridSpec to build a pair of axes where the raw_used_fit axis is 3 times the resid_axis. Additionally, if fit_resid_axes is None, the hax and rax will share an x-axis and hax’s x-ticks and label will be set invisible.

  • figsize – Any valid argument for plt.figure(figsize=figsize)(). This code was developed with default size 6x4 and this size helps accomodate annotation. So we persist it here.

  • resid_kwargs (dict, None) – Passed to {self.__class__.__name__}.plot_residuals().

  • kwargs – Passed to {self.__class__.__name__}.plot_raw_used_fit().

Returns:

  • hax (mpl.axis.Axis) – Axis with raw observations, used observations, and fit plotted on it.

  • rax (mpl.axis.Axis) – Axis with residuals plotted on it.

residuals(pct=False, robust=False)[source]

Calculate the fit residuals.

If pct, normalize by fit yvalues.

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_log(**kwargs)[source]

Set LogAxes.

Only used for determining if weights should be \(w/(y \ln(10))\).

set_TeX_info(new)[source]

Assign TeXinfo used for annotations.