Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default matplotlib style?

When using matplotlib, I tend to use

import matplotlib.pyplot as plt
plt.style.use('ggplot')

quiet often. Is there an easy way to change the default style to ggplot (or any other style)? I looked into the 'matplotlibrc'-documentation but was unable to find an appropriate option.

Is there a better way then copying/linking the system-wide .mplstyle?

Thanks!

like image 819
dassmann Avatar asked May 07 '15 14:05

dassmann


2 Answers

You can change the settings file of matplotlib. According to the docs :

matplotlib uses matplotlibrc configuration files to customize all kinds of properties, which we call rc settings or rc parameters. You can control the defaults of almost every property in matplotlib: figure size and dpi, line width, color and style, axes, axis and grid properties, text and font properties and so on.

You can locate your matplotlibrc file with the following command:

import matplotlib
matplotlib.matplotlib_fname()

Hence we can put ggplot settings at the end of the matplotlibrc file. You can easily find ggplot style (as well as other styles) on official matplotlib repository.

like image 159
arthur Avatar answered Nov 01 '22 05:11

arthur


Apparently, there is no such option (yet).

However, you can tell iPython to load the ggplot style at startup, by adding "plt.style.use('ggplot')" to c.InteractiveShellApp.exec_lines in ipython_config.py.

like image 3
Toby Avatar answered Nov 01 '22 06:11

Toby