One minute
Custom Matplotlib style
Matplotlib offers different plotting styles out of the box, which you can visualize here. You can also find out which styles are available to you by running plt.style.available
. It will return a list of styles you can use and then set the one you want by running plt.style.use('tableau-colorblind10')
.
But what if you would like to create your own Matlplotlib style?
Custom matplotlib style
To create your own Matplotlib style, create a file with a .mplstyle
file containing your favorite settings. For a list of all the settings available, see this link.
Below is my signature matplotlib style, saved as signature.mplstyle
:
# signature.mplstyle
### FIGURE
figure.figsize : 12, 6
### TICKS
xtick.labelsize: 13
ytick.labelsize: 13
### LEGEND
legend.fontsize: 15
#legend.loc: upper left
### AXES
axes.grid: True
axes.titlesize: 15
axes.labelsize: 15
axes.prop_cycle: cycler('color', ['8da0cb','fc8d62','ffd92f','66c2a5','e78ac3','a6d854','e5c494','b3b3b3'])
# Other nice options for the color cycle:
# Seaborn: ['f77189','dc8932','ae9d31','77ab31','33b07a','36ada4','38a9c5','6e9bf4','cc7af4','f565cc']
# MATLAB: ['0072BE','DA5319','EEB420','7E2f8E','77AD30','4DBEEF','A3142E']
# Dark 2: ['1B9E77','D95F02','7570B3','E7298A','66A61E','E6AB02','A6761D','666666']
# Set 1: ['e41a1c','377eb8','4daf4a','984ea3','ff7f00','ffff33','a65628','f781bf']
# Set 2: ['66c2a5','fc8d62','8da0cb','e78ac3','a6d854','ffd92f','e5c494','b3b3b3']
# Set 2 (re-ordered): ['8da0cb','fc8d62','ffd92f','66c2a5','e78ac3','a6d854','e5c494','b3b3b3']
# Set 3: ['8dd3c7','ffffb3','bebada','fb8072','80b1d3','fdb462','b3de69','fccde5','d9d9d9','bc80bd','ccebc5','ffed6f']
Now when you open a Python notebook, start with the following lines:
import matplotlib.pyplot as plt
plt.style.use('../signature.mplstyle') # replace path to your own mplstyle file
192 Words
2022-05-02 15:11