2

I am Using iPython with python 2.7 and matplotlib 1.5 in Anaconda

print matplotlib.get_configdir()
>>> /Users/rpickhardt/.matplotlib

When I check the directory I find:

PigPen:.matplotlib rpickhardt$ pwd
>>> /Users/rpickhardt/.matplotlib
PigPen:.matplotlib rpickhardt$ ls
>>> fontList.cache  tex.cache

Following the matplotlib stylesheet documentation I am confused because I expected to find a folder called stylelib since python tells me there are some style sheets available.

print plt.style.available`
>>> [u'dark_background', u'bmh', u'grayscale', u'ggplot', u'fivethirtyeight']

So I think maybe there is no need for the standard styles to be in the config folder and I create stylelib/presentation.mplstyle but

plt.style.use('presentation')

results in

ValueError                                Traceback (most recent call last)
<ipython-input-285-d7cf43d778d5> in <module>()
      1 matplotlib.style.core.reload_library()
----> 2 plt.style.use('presentation')

/Users/rpickhardt/anaconda/lib/python2.7/site-packages/matplotlib/style/core.pyc in use(name)
     64                        "not a valid URL or path. See `style.available` for "
     65                        "list of available styles.")
---> 66                 raise ValueError(msg % style)
     67 
     68 

ValueError: 'presentation' not found in the style library and input is not a valid URL or path. See `style.available` for list of available styles.

So how can I now add a stylesheet or edit one of the predefined ones?

Rene Pickhardt
  • 692
  • 5
  • 17

2 Answers2

2

I was just having the same issue (three years after the original post) using Python 3 in Jupyter Notebook in Anaconda. I found the solution: create the stylelib folder in the configuration directory you find using

>>> matplotlib.get_configdir()
'/Users/{username}/.matplotlib'

so it looks like

/Users/{username}/.matplotlib/stylelib

then save your custom style in the new folder (e.g. mystyle.mlpstyle) then run

matplotlib.style.reload_library()

and you'll be good to go with your custom style!

0

While asking the question the recommendation system showed this discussion about exporting custom stylesheets which gave the hint of using:

matplotlib.style.core.reload_library()

which did the job for me.

Community
  • 1
  • 1
Rene Pickhardt
  • 692
  • 5
  • 17