Customizing matplotlib with style
The default style configuration of matplotlib is made to satisfy the requirements of a wide audience, but this means that we always have to spend some time customizing the details that we care about. In this recipe, we want to show how to create custom and reusable styles for matplotlib so that we make our changes only once.
Getting ready
All the styles that matplotlib can use are stored in a directory called stylelib
, under the configuration directory of matplotlib. To check the path of this directory, we can use the get_configdir()
method:
In [1]: import matplotlib In [2]: matplotlib.get_configdir() Out[2]: u'~/.matplotlib'
In this directory we will store the files that specify our custom styles.
How to do it...
First, we will create the file that contains all the specifications of our style:
axes.titlesize : 12 lines.linewidth : 2 xtick.labelsize : 8 ytick.labelsize : 8 figure.facecolor: white figure.edgecolor: 555555 xtick.color: 555555 axes.color_cycle:...