Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib style library not updating when .mplstyle files added/deleted

I'm trying to create my own matplotlib stylesheets but Python doesn't detect them. Even worse: when I moved one of the five default stylesheets (ggplot.mplstyle), Python kept reporting it was availabe.

I tried to reload the entire module but to no avail:

import matplotlib
reload(matplotlib)
from matplotlib import style as style
plt = matplotlib.pyplot
print plt.style.available

just keeps returning

[u'dark_background', u'bmh', u'grayscale', u'ggplot', u'fivethirtyeight']

How can I force a "refresh" of these styles?

P.s. I'm not a Python expert.

like image 283
RubenGeert Avatar asked Sep 29 '14 18:09

RubenGeert


People also ask

How do I change the plot style in Matplotlib?

Another way to change the visual appearance of plots is to set the rcParams in a so-called style sheet and import that style sheet with matplotlib. style. use . In this way you can switch easily between different styles by simply changing the imported style sheet.

What is style use (' Fivethirtyeight ') in Python?

Another example of a style is from fivethirtyeight: style. use('fivethirtyeight') You can see all of the available styles you currently have by doing: print(plt. style.

What does rcParams do in Python?

Changing the Defaults: rcParams Each time Matplotlib loads, it defines a runtime configuration (rc) containing the default styles for every plot element you create. This configuration can be adjusted at any time using the plt. rc convenience routine.


1 Answers

Just in case someone else stumbles on this post, this issue was reported and resolved here:

https://github.com/matplotlib/matplotlib/issues/3601

Basically, the style library looks for files in a subdirectory of the matplotlib config directory. On linux/osx system, this would be something like ~/.matplotlib/stylelib/<my-custom-style>.mplstyle.

Also, as @tcaswell suggested in comments, loading is done at import time, so style files added or edited after import will not work without a call to plt.style.reload_library().

like image 139
Tony S Yu Avatar answered Sep 21 '22 12:09

Tony S Yu