aerosandbox.tools.pretty_plots.formatting#

Module Contents#

Functions#

show_plot([title, xlabel, ylabel, zlabel, dpi, ...])

Makes a matplotlib Figure (and all its constituent Axes) look "nice", then displays it.

set_ticks([x_major, x_minor, y_major, y_minor, ...])

equal()

Sets all axes to be equal. Works for both 2d plots and 3d plots.

aerosandbox.tools.pretty_plots.formatting.show_plot(title=None, xlabel=None, ylabel=None, zlabel=None, dpi=None, savefig=None, savefig_transparent=False, tight_layout=True, legend=None, legend_inline=False, legend_frame=True, pretty_grids=True, set_ticks=True, rotate_axis_labels=True, rotate_axis_labels_linewidth=14, show=True)[source]#

Makes a matplotlib Figure (and all its constituent Axes) look “nice”, then displays it.

Arguments control whether various changes (from the default matplotlib settings) are made to the plot.

One argument in particular, show (a boolean), controls whether the plot is displayed.

Parameters:
  • title (str) – If given, sets the title of the plot. If the Figure has multiple axes, this sets the Figure-level suptitle instead of setting the individual Axis title.

  • xlabel (str) – If given, sets the xlabel of all axes. (Equivalent to ax.set_xlabel(my_label))

  • ylabel (str) – If given, sets the ylabel of all axes. (Equivalent to ax.set_ylabel(my_label))

  • zlabel (str) – If given, sets the zlabel of all axes, if the axis is 3D. (Equivalent to ax.set_zlabel(my_label))

  • dpi (float) – If given, sets the dpi (display resolution, in Dots Per Inch) of the Figure.

  • savefig (Union[str, List[str]]) –

    If given, saves the figure to the given path(s).

    • If a string is given, saves the figure to that path.

      (E.g., savefig=”my_plot.png”)

    • If a list of strings is given, saves the figure to each of those paths.

      (E.g., savefig=[“my_plot.png”, “my_plot.pdf”])

  • savefig_transparent (bool) – If True, saves the figure with a transparent background. If False, saves the figure with a white background. Only has an effect if savefig is not None.

  • tight_layout (bool) – If True, calls plt.tight_layout() to adjust the spacing of individual Axes. If False, skips this step.

  • legend (bool) –

    This value can be True, False, or None.

    • If True, displays a legend on the current Axis.

    • If False, does not add a legend on the current Axis. (However, does not delete any existing legends.)

    • If None (default), goes through some logic to determine whether a legend should be displayed. If there

      is only one line on the current Axis, no legend is displayed. If there are multiple lines, a legend is ( in general) displayed.

  • legend_inline (bool) –

    Boolean that controls whether an “inline” legend is displayed.

    • If True, displays an “inline” legend, where the labels are next to the lines instead of in a box.

    • If False (default), displays a traditional legend.

    Only has an effect if legend=True (or legend=None, and logic determines that a legend should be displayed).

  • legend_frame (bool) – Boolean that controls whether a frame (rectangular background box) is displayed around the legend. Default is True.

  • pretty_grids (bool) – Boolean that controls whether the gridlines are formatted have linewidths that are (subjectively) more readable.

  • set_ticks (bool) –

    Boolean that controls whether the tick and grid locations + labels are formatted to be ( subjectively) more readable.

    Works with both linear and log scales, and with both 2D and 3D plots.

  • show (bool) – Boolean that controls whether the plot is displayed after all plot changes are applied. Default is True. You may want to set this to False if you want to make additional manual changes to the plot before displaying it. Default is True.

  • rotate_axis_labels (bool) –

  • rotate_axis_labels_linewidth (int) –

Returns: None (completely in-place function). If show=True (default), displays the plot after applying changes.

aerosandbox.tools.pretty_plots.formatting.set_ticks(x_major=None, x_minor=None, y_major=None, y_minor=None, z_major=None, z_minor=None)[source]#
Parameters:
  • x_major (Union[float, int]) –

  • x_minor (Union[float, int]) –

  • y_major (Union[float, int]) –

  • y_minor (Union[float, int]) –

  • z_major (Union[float, int]) –

  • z_minor (Union[float, int]) –

aerosandbox.tools.pretty_plots.formatting.equal()[source]#

Sets all axes to be equal. Works for both 2d plots and 3d plots.

Returns: None

Return type:

None