dassmann
dassmann

Reputation: 337

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!

Upvotes: 8

Views: 12194

Answers (4)

iamakhilverma
iamakhilverma

Reputation: 596

plt.style.use('default') worked for me.

As I understand this, it tells matplotlib to switch back to its default style mode.

Upvotes: 1

arthur
arthur

Reputation: 348

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.

Upvotes: 6

Dmitri
Dmitri

Reputation: 811

Create a file (call it e.g. startup-01.py) in ~/.ipython/profile_default/startup/

(substitute another profile name for profile_default as needed)

and put there any needed notebook (and interactive ipython) initialization statements, including

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

## other settings, e.g.
# plt.rcParams['figure.figsize'] = (10.0, 8.0)

Upvotes: 2

Toby
Toby

Reputation: 2294

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.

Upvotes: 4

Related Questions