aerosandbox.tools.pretty_plots.plots
Submodules
- aerosandbox.tools.pretty_plots.plots.contour
- aerosandbox.tools.pretty_plots.plots.pie
- aerosandbox.tools.pretty_plots.plots.plot_color_by_value
- aerosandbox.tools.pretty_plots.plots.plot_smooth
- aerosandbox.tools.pretty_plots.plots.plot_with_bootstrapped_uncertainty
Attributes
Functions
eng_string(x[, unit, format, si, add_space_after_number]) | Taken from: https://stackoverflow.com/questions/17973278/python-decimal-engineering-notation-for-mili-10e-3-and-micro-10e-6/40691220 |
contour(*args[, levels, colorbar, linelabels, cmap, ...]) | An analogue for plt.contour and plt.tricontour and friends that produces a much prettier default graph. |
eng_string(x[, unit, format, si, add_space_after_number]) | Taken from: https://stackoverflow.com/questions/17973278/python-decimal-engineering-notation-for-mili-10e-3-and-micro-10e-6/40691220 |
pie(values, names[, colors, label_format, sort_by, ...]) | |
plot_color_by_value(x, y, *args, c[, cmap, colorbar, ...]) | Uses same syntax as matplotlib.pyplot.plot, except that c is now an array-like that maps to a specific color |
plot_smooth(*args[, color, label, function_of, ...]) | Plots a curve that interpolates a 2D dataset. Same as matplotlib.pyplot.plot(), with the following changes: |
plot_with_bootstrapped_uncertainty(x, y[, ci, ...]) |
Package Contents
aerosandbox.tools.pretty_plots.plots.eng_string(x, unit='', format='%.3g', si=True, add_space_after_number=None) : Taken from: https://stackoverflow.com/questions/17973278/python-decimal-engineering-notation-for-mili-10e-3-and-micro-10e-6/40691220
Returns float/int value <x> formatted in a simplified engineering format -
using an exponent that is a multiple of 3.
Parameters:
: - **x** (*float*) – The value to be formatted. Float or int.
- **unit** (*str*) – A unit of the quantity to be expressed, given as a string. Example: Newtons -> “N”
- **format** – A printf-style string used to format the value before the exponent.
- **si** – if true, use SI suffix for exponent. (k instead of e3, n instead of
e-9, etc.)
- **add\_space\_after\_number** (*bool*) –
Return type:
: str
Examples:
With format=’%.2f’:
: > 1.23e-08 -> 12.30e-9
> : > 123 -> 123.00
>
> 1230.0 -> 1.23e3
-1230000.0 -> -1.23e6
With si=True:
: > 1230.0 -> “1.23k”
-1230000.0 -> “-1.23M”
With unit=”N” and si=True:
: > 1230.0 -> “1.23 kN”
-1230000.0 -> “-1.23 MN”aerosandbox.tools.pretty_plots.plots.contour(*args, levels=31, colorbar=True, linelabels=True, cmap=None, alpha=0.7, extend='neither', linecolor='k', linewidths=0.5, extendrect=True, linelabels_format=eng_string, linelabels_fontsize=8, max_side_length_nondim=np.inf, colorbar_label=None, x_log_scale=False, y_log_scale=False, z_log_scale=False, mask=None, drop_nans=None, contour_kwargs=None, contourf_kwargs=None, colorbar_kwargs=None, linelabels_kwargs=None, **kwargs) : An analogue for plt.contour and plt.tricontour and friends that produces a much prettier default graph.
Can take inputs with either contour or tricontour syntax.
See syntax here:
: <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html>
<https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html>
<https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tricontour.html>
<https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tricontourf.html>
Parameters:
: - **X** – If dataset is gridded, follow contour syntax. Otherwise, follow tricontour syntax.
- **Y** – If dataset is gridded, follow contour syntax. Otherwise, follow tricontour syntax.
- **Z** – If dataset is gridded, follow contour syntax. Otherwise, follow tricontour syntax.
- **levels** (*Union**[**int**,* *List**,* *numpy.ndarray**]*) – See contour docs.
- **colorbar** (*bool*) – Should we draw a colorbar?
- **linelabels** (*bool*) – Should we add line labels?
- **cmap** – What colormap should we use?
- **alpha** (*float*) – What transparency should all plot elements be?
- **extend** (*str*) – See contour docs.
- **linecolor** – What color should the line labels be?
- **linewidths** (*float*) – See contour docs.
- **extendrect** (*bool*) – See colorbar docs.
- **linelabels\_format** (*Union**[**str**,* *Callable**[**[**float**]**,* *str**]**]*) – See ax.clabel docs.
- **linelabels\_fontsize** (*float*) – See ax.clabel docs.
- **contour\_kwargs** (*Dict*) – Additional keyword arguments for contour.
- **contourf\_kwargs** (*Dict*) – Additional keyword arguments for contourf.
- **colorbar\_kwargs** (*Dict*) – Additional keyword arguments for colorbar.
- **linelabels\_kwargs** (*Dict*) – Additional keyword arguments for the line labels (ax.clabel).
- **\*\*kwargs** – Additional keywords, which are passed to both contour and contourf.
- **max\_side\_length\_nondim** (*float*) –
- **colorbar\_label** (*str*) –
- **x\_log\_scale** (*bool*) –
- **y\_log\_scale** (*bool*) –
- **z\_log\_scale** (*bool*) –
- **mask** (*numpy.ndarray*) –
- **drop\_nans** (*bool*) –
Returns: A tuple of (contour, contourf, colorbar) objects.aerosandbox.tools.pretty_plots.plots.x
aerosandbox.tools.pretty_plots.plots.eng_string(x, unit='', format='%.3g', si=True, add_space_after_number=None) : Taken from: https://stackoverflow.com/questions/17973278/python-decimal-engineering-notation-for-mili-10e-3-and-micro-10e-6/40691220
Returns float/int value <x> formatted in a simplified engineering format -
using an exponent that is a multiple of 3.
Parameters:
: - **x** (*float*) – The value to be formatted. Float or int.
- **unit** (*str*) – A unit of the quantity to be expressed, given as a string. Example: Newtons -> “N”
- **format** – A printf-style string used to format the value before the exponent.
- **si** – if true, use SI suffix for exponent. (k instead of e3, n instead of
e-9, etc.)
- **add\_space\_after\_number** (*bool*) –
Return type:
: str
Examples:
With format=’%.2f’:
: > 1.23e-08 -> 12.30e-9
> : > 123 -> 123.00
>
> 1230.0 -> 1.23e3
-1230000.0 -> -1.23e6
With si=True:
: > 1230.0 -> “1.23k”
-1230000.0 -> “-1.23M”
With unit=”N” and si=True:
: > 1230.0 -> “1.23 kN”
-1230000.0 -> “-1.23 MN”aerosandbox.tools.pretty_plots.plots.pie(values, names, colors=None, label_format=lambda name, value, percentage: ..., sort_by=None, startangle=0.0, center_text=None, x_labels=1.25, y_max_labels=1.3, arm_length=20, arm_radius=5) : Parameters: : - values (Union[numpy.ndarray, List[float]**]) – - names (List[str]) – - colors (Union[numpy.ndarray, List[str]**]) – - label_format (Callable[**[str, float, float]**, str]) – - sort_by (Union[numpy.ndarray, List[float]**, str, None]) – - startangle (float) – - center_text (str) – - x_labels (float) – - y_max_labels (float) –
aerosandbox.tools.pretty_plots.plots.data
aerosandbox.tools.pretty_plots.plots.plot_color_by_value(x, y, *args, c, cmap='turbo', colorbar=False, colorbar_label=None, clim=None, **kwargs) : Uses same syntax as matplotlib.pyplot.plot, except that c is now an array-like that maps to a specific color pulled from cmap. Makes lines that are multicolored based on this c value.
Parameters:
: - **x** (*numpy.ndarray*) – Array of x-points.
- **y** (*numpy.ndarray*) – Array of y-points.
- **\*args** – Args that will be passed into matplotlib.pyplot.plot().
Example: “.-” for a dotted line.
- **c** (*numpy.ndarray*) – Array of values that will map to colors. Must be the same length as x and y.
- **cmap** – The colormap to use.
- **colorbar** (*bool*) – Whether or not to display the colormap. [bool]
- **colorbar\_label** (*str*) – The label to add to the colorbar. Only applies if the colorbar is created. [str]
- **clim** (*Tuple**[**float**,* *float**]*) – A tuple of (min, max) that assigns bounds to the colormap. Computed from the range of c if not given.
- **\*\*kwargs** – Kwargs that will be passed into matplotlib.pyplot.plot()
Returns:aerosandbox.tools.pretty_plots.plots.x
aerosandbox.tools.pretty_plots.plots.plot_smooth(*args, color=None, label=None, function_of=None, resample_resolution=500, drop_nans=False, **kwargs) : 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:
: ```defaultimport 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], [\*](#id2), data=None, [\*\*](#id4)kwargs)
> >>> plot([x], y, [fmt], [x2], y2, [fmt2], …, [\*\*](#id6)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.x
aerosandbox.tools.pretty\_plots.plots.plot\_with\_bootstrapped\_uncertainty(*x*, *y*, *ci=0.95*, *x\_stdev=0.0*, *y\_stdev=None*, *color=None*, *draw\_data=True*, *label\_line='Best Estimate'*, *label\_ci=True*, *label\_data='Raw Data'*, *line\_alpha=0.9*, *ci\_to\_alpha\_mapping=lambda ci: ...*, *n\_bootstraps=2000*, *n\_fit\_points=500*, *spline\_degree=3*, *normalize=True*, *x\_log\_scale=False*, *y\_log\_scale=False*)
: Parameters:
: - **x** (*numpy.ndarray*) –
- **y** (*numpy.ndarray*) –
- **ci** (*Optional**[**Union**[**float**,* *Iterable**[**float**]**,* *numpy.ndarray**]**]*) –
- **x\_stdev** (*Union**[**None**,* *float**]*) –
- **y\_stdev** (*Union**[**None**,* *float**]*) –
- **color** (*Optional**[**Union**[**str**,* *Tuple**[**float**]**]**]*) –
- **draw\_data** (*bool*) –
- **label\_line** (*Union**[**bool**,* *str**]*) –
- **label\_ci** (*bool*) –
- **label\_data** (*Union**[**bool**,* *str**]*) –
- **line\_alpha** (*float*) –
- **ci\_to\_alpha\_mapping** (*Callable**[**[**float**]**,* *float**]*) –
- **normalize** (*bool*) –
- **x\_log\_scale** (*bool*) –
- **y\_log\_scale** (*bool*) –
<a id="id9"></a> aerosandbox.tools.pretty\_plots.plots.x