-
matplotlib
can accept a manually defined stylesheet file that is located remotely or locally. -
To use the BillingeGroup stylesheet, please install this package first
-
It is recommended to install using conda:
conda install -c conda-forge bg-mpl-stylesheets
-
To get cutting edge updates you can install in develop mode from the source code in this repo by typing
python setup.py develop
.
-
-
By default the package uses LaTeX fonts for mathematical symbols. This feature requires a Latex package on your computer. It is not required for the use of the styel-sheet but gives better results for things like angstrom symbols. Matplotlib will look for your installed latex package, for example TeXLive or MikTex. If it can't find a latex package it will look for non-latex font replacements.
-
To use the stylesheet, near the beginning your python script type the.
from bg_mpl_stylesheet.bg_mpl_stylesheet import <style-sheet-name> plt.style.use(<style-sheet-name>)
for example
from bg_mpl_stylesheet.bg_mpl_stylesheet import bg_mpl_style plt.style.use(bg_mpl_style)
-
If you wish to use BillingeGroup stylesheet as the default style for all your plots, please follow these steps.
-
Use following commands to figure out which matplotlib config directory on your system:
import matplotlib config_dir = matplotlib.get_configdir()
-
Copy and paste the
bg_mpl_stylesheet
file to theconfig_dir
found in the previous step.
-
-
You can configure any matplotlib style parameter by updating its value in the
rcParams
dictionary dynamically in your python session, For example, by typingplt.rcParams['figure.dpi'] = 180 plt.rcParams['font.size'] = 18 (... and so on)
Not that the
rcParams
are global. It can get very confusing if these are updated everywhere in the code. It is much better to make local updates to their values by defining functions for your plots and using the @matplotlib.style.context() decorator, e.g.,import matplotlib.pyplot as plt @mpl.rc_context({'lines.linewidth': 1, 'axes.linewidth': 0.7, 'xtick.major.size': 0.7, 'xtick.major.width': 0.7, 'xtick.labelsize': 5, 'legend.frameon': False, 'legend.loc': 'best', 'font.size': 5, 'axes.labelsize': 5, 'ytick.left': False, 'ytick.labelleft': False, 'ytick.right': False }) def all_plot(x-array, yarray): plt.plot(x-array, y-array) plt.ylabel('some numbers') plt.show() return
This will confine the style updates to just apply in the function namespace.
-
You can also update style parameters locally by using the matplotlib style context manager, for example
with plot.style.context(<new_stylesheet>): plt.plot(x-array, y-array) plt.ylabel('some numbers') plt.show()
- You can also go to the
example
folder and runplot.py
for testing. The example plot would be like this:
- The full group color cycle is shown in the following along with the color codes:
- For full reference, please see matplotlib doc: https://matplotlib.org/users/dflt_style_changes.html
Please feel encouraged to contribute your own style-sheets to the package and make your beautiful styles more widely available. To do so, fork the repo, create a branch and make a Pull Request.