aerosandbox.tools.pretty_plots.plots.plot_smooth#

Module Contents#

Functions#

plot_smooth(*args[, color, label, function_of, ...])

Plots a curve that interpolates a 2D dataset. Same as matplotlib.pyplot.plot(), with the following changes:

Attributes#

x

aerosandbox.tools.pretty_plots.plots.plot_smooth.plot_smooth(*args, color=None, label=None, function_of=None, resample_resolution=500, drop_nans=False, **kwargs)[source]#
Plots a curve that interpolates a 2D dataset. Same as matplotlib.pyplot.plot(), with the following changes:
  • uses B-splines to draw a smooth curve rather than a jagged polyline

  • By default, plots in line format fmt=’.-’ rather than fmt=’-’.

Other than that, almost all matplotlib.pyplot.plot() syntax can be used. See syntax here: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html

Example usage:
>>> import aerosandbox.numpy as np
>>>
>>> t = np.linspace(0, 1, 12)  # Parametric variable
>>> x = np.cos(2 * np.pi * t)
>>> y = np.cos(2 * np.pi * t ** 4) - t
>>>
>>> plot_smooth(
>>>     x, y, 'o--', color='purple'
>>> )
>>> plt.show()
  • Note: a true 2D interpolation is performed - it is not assumed y is a function of x, or vice versa. This can,

in rare cases, cause single-valuedness to not be preserved in cases where it logically should. If this is the case, you need to perform the interpolation yourself without plot_smooth().

Parameters:
  • *args

    Same arguments as matplotlib.pyplot.plot(). Notes on standard plot() syntax:

    Call signatures: >>> plot([x], y, [fmt], *, data=None, **kwargs) >>> plot([x], y, [fmt], [x2], y2, [fmt2], …, **kwargs)

    Examples: >>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, ‘bo’) # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, ‘r+’) # ditto, but with red plusses

  • color – Specifies the color of any line and/or markers that are plotted (as determined by the fmt).

  • label – Attaches a label to this line. Use plt.legend() to display.

  • resample_resolution (int) – The number of points to use when resampling the interpolated curve.

  • **kwargs – Same keyword arguments as matplotlib.pyplot.plot().

  • function_of (str) –

  • drop_nans (bool) –

Return type:

Tuple[aerosandbox.numpy.ndarray, aerosandbox.numpy.ndarray]

Returns: A tuple (x, y) of the resampled points on the interpolated curve. Both x and y are 1D ndarrays.

aerosandbox.tools.pretty_plots.plots.plot_smooth.x[source]#