datopy.stylesheet#
Description
Plotting utilities and matplotlib rcParams customization.
- class outputoff[source]#
Bases:
objectDefine a context in which all outputs are suppressed.
Intended for use with pyplot to suppress intermittent printouts.
- customize_plots() None[source]#
Set custom matplotlib rcParams.
Handles default styling for all matplotlib plotting functions and functions built upon matplotlib (e.g., Seaborn plotters).
Notes
Contrast with the default matplotlib rc file: https://matplotlib.org/stable/users/explain/customizing.html#the-matplotlibrc-file.
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(x): ... 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$", frame_on=False) ... ax.set_ylabel("$f(x)$", rotation=0) ... ax.legend() ... ax.grid() ... plt.show()
>>> def multi_panel_plot(x): ... 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.text( ... max(x) - 0.1, -1 + 0.1, ... f"$a = {i/2}$", ... size=12, ... ha="right", ... bbox={ ... "boxstyle": "round", ... "alpha": 0.8, ... "facecolor": "white", ... } ... ) ... ax.grid() ... fig.supylabel("$f(x)$", rotation=0) ... fig.supxlabel("$x$", x=.5) ... axs[0].legend( ... labels=["$sin(ax)$", "$cos(ax)$"], ... ncol=1, ... loc="lower left", ... ) ... plt.show()
Create the plots
>>> customize_plots() >>> single_panel_plot(x) # /doctest: +SKIP >>> multi_panel_plot(x) # /doctest: +SKIP
- class customstyle[source]#
Bases:
objectDefine plotting context given by
datopy.stylesheet.customize_plots().Examples
Classes
Define plotting context given by |
|
Define a context in which all outputs are suppressed. |
Functions
Set custom matplotlib rcParams. |