datopy.stylesheet#

Description

A helper function that updates the default matplotlib (and by extension, Seaborn) style parameters for a more uniform and readable look.

customize_plots() None[source]#

Sets custom matplotlib rcParams to handle default styling for all matplotlib plotting functions and functions built upon matplotlib (e.g., Seaborn).

Notes

Examples

>>> import matplotlib
>>> import matplotlib.pyplot as plt
>>> from datopy.stylesheet import customize_plots

Define some data

>>> import numpy as np
>>> x = np.linspace(0, 2 * np.pi, 1000)

Define a couple plotting functions

>>> def single_panel_plot():
...     ax = plt.subplot(111)
...     ax.plot(x, np.sin(x), label="$sin(x)$")
...     ax.plot(x, np.cos(x), label="$cos(x)$")
...     ax.set_xlabel('$x$')
...     ax.set_ylabel('$y$')
...     # ax.set_title("A minimal plot")
...     ax.legend()
...     ax.grid()
...     ax.set_frame_on(False)
...     # ax.tick_params(bottom=False, left=False)
...     plt.show()
>>> def multi_panel_plot():
...     fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
...     axs = axs.flatten()
...     for i, ax in enumerate(axs, start=1):
...         ax.plot(x, np.sin(i/2 * x))
...         ax.plot(x, np.cos(i/2 * x))
...         # ax.set_title(f"$a = {i}$")
...         # if i > 2: ax.set_xlabel('$x$')
...         # if i % 2 != 0: ax.set_ylabel('$y$')
...         ax.grid()
...         ax.text(
...             2 * np.pi - 0.1, -1 + 0.1,
...             f"$a = {i}$",
...             size=12,
...             horizontalalignment="right",
...             bbox={
...                 "boxstyle": "round",
...                 "alpha": 0.8,
...                 "facecolor": "white",
...             }
...         )
...     fig.supylabel("$y$")
...     fig.supxlabel("$x$", x=.57)
...     # fig.suptitle("A multi-panel plot", x=.57)
...     axs[0].legend(
...         labels=["$sin(ax)$", "$cos(ax)$"],
...         ncol=1,
...         loc="lower left",
...     )
...     plt.show()

Create the plots

>>> customize_plots()
>>> single_panel_plot()  # /doctest: +SKIP
>>> multi_panel_plot()  # /doctest: +SKIP
../_images/datopy-stylesheet-1_00.svg
../_images/datopy-stylesheet-1_01.svg
class customstyle[source]#

Bases: object

Wrapper and context manager for customize_plots.

Examples

class outputoff[source]#

Bases: object

Context manager to suppress outputs. Intended for use with pyplot to suppress intermittent printouts.

Classes

customstyle()

Wrapper and context manager for customize_plots.

outputoff()

Context manager to suppress outputs.

Functions

customize_plots()

Sets custom matplotlib rcParams to handle default styling for all matplotlib plotting functions and functions built upon matplotlib (e.g., Seaborn).