datopy.stylesheet.customize_plots#
- 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
When run in isolation, will apply the new style parameters globally.
When provided as context to a plotting routine, styles only that plot.
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(): ... 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