aerosandbox.tools.pretty_plots.plots ==================================== .. py:module:: aerosandbox.tools.pretty_plots.plots Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/aerosandbox/tools/pretty_plots/plots/contour/index /autoapi/aerosandbox/tools/pretty_plots/plots/pie/index /autoapi/aerosandbox/tools/pretty_plots/plots/plot_color_by_value/index /autoapi/aerosandbox/tools/pretty_plots/plots/plot_smooth/index /autoapi/aerosandbox/tools/pretty_plots/plots/plot_with_bootstrapped_uncertainty/index Attributes ---------- .. autoapisummary:: aerosandbox.tools.pretty_plots.plots.x aerosandbox.tools.pretty_plots.plots.data aerosandbox.tools.pretty_plots.plots.x aerosandbox.tools.pretty_plots.plots.x aerosandbox.tools.pretty_plots.plots.x Functions --------- .. autoapisummary:: aerosandbox.tools.pretty_plots.plots.eng_string aerosandbox.tools.pretty_plots.plots.contour aerosandbox.tools.pretty_plots.plots.eng_string 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 Package Contents ---------------- .. py:function:: 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 formatted in a simplified engineering format - using an exponent that is a multiple of 3. :param x: The value to be formatted. Float or int. :param unit: A unit of the quantity to be expressed, given as a string. Example: Newtons -> "N" :param format: A printf-style string used to format the value before the exponent. :param si: if true, use SI suffix for exponent. (k instead of e3, n instead of e-9, etc.) 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" .. py:function:: 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 :param X: If dataset is gridded, follow `contour` syntax. Otherwise, follow `tricontour` syntax. :param Y: If dataset is gridded, follow `contour` syntax. Otherwise, follow `tricontour` syntax. :param Z: If dataset is gridded, follow `contour` syntax. Otherwise, follow `tricontour` syntax. :param levels: See contour docs. :param colorbar: Should we draw a colorbar? :param linelabels: Should we add line labels? :param cmap: What colormap should we use? :param alpha: What transparency should all plot elements be? :param extend: See contour docs. :param linecolor: What color should the line labels be? :param linewidths: See contour docs. :param extendrect: See colorbar docs. :param linelabels_format: See ax.clabel docs. :param linelabels_fontsize: See ax.clabel docs. :param contour_kwargs: Additional keyword arguments for contour. :param contourf_kwargs: Additional keyword arguments for contourf. :param colorbar_kwargs: Additional keyword arguments for colorbar. :param linelabels_kwargs: Additional keyword arguments for the line labels (ax.clabel). :param \*\*kwargs: Additional keywords, which are passed to both contour and contourf. Returns: A tuple of (contour, contourf, colorbar) objects. .. py:data:: x .. py:function:: 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 formatted in a simplified engineering format - using an exponent that is a multiple of 3. :param x: The value to be formatted. Float or int. :param unit: A unit of the quantity to be expressed, given as a string. Example: Newtons -> "N" :param format: A printf-style string used to format the value before the exponent. :param si: if true, use SI suffix for exponent. (k instead of e3, n instead of e-9, etc.) 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" .. py:function:: pie(values, names, colors = None, label_format = lambda name, value, percentage: name, sort_by = None, startangle = 0.0, center_text = None, x_labels = 1.25, y_max_labels = 1.3, arm_length=20, arm_radius=5) .. py:data:: data .. py:function:: 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. :param x: Array of x-points. :param y: Array of y-points. :param \*args: Args that will be passed into matplotlib.pyplot.plot(). Example: ".-" for a dotted line. :param c: Array of values that will map to colors. Must be the same length as x and y. :param cmap: The colormap to use. :param colorbar: Whether or not to display the colormap. [bool] :param colorbar_label: The label to add to the colorbar. Only applies if the colorbar is created. [str] :param clim: A tuple of (min, max) that assigns bounds to the colormap. Computed from the range of `c` if not given. :param \*\*kwargs: Kwargs that will be passed into matplotlib.pyplot.plot() Returns: .. py:data:: x .. py:function:: 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: >>> 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()`. :param \*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 :param color: Specifies the color of any line and/or markers that are plotted (as determined by the `fmt`). :param label: Attaches a label to this line. Use `plt.legend()` to display. :param resample_resolution: The number of points to use when resampling the interpolated curve. :param \*\*kwargs: Same keyword arguments as `matplotlib.pyplot.plot()`. Returns: A tuple `(x, y)` of the resampled points on the interpolated curve. Both `x` and `y` are 1D ndarrays. .. py:data:: x .. py:function:: 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: 0.8 * (1 - ci)**0.4, n_bootstraps=2000, n_fit_points=500, spline_degree=3, normalize = True, x_log_scale = False, y_log_scale = False) .. py:data:: x