1

I'd like to overide the axes.prop_cycle defined in a matplotlib stylesheet that I'm using matplotlib.pyplot.rcParams to avoid needing to use matplotlib.pyplot.gca().set_prop_cycle(None) during each call to the plots I'm creating which is suggested in this SO answer.

Based on the docs I'm using somethings like this:

import matplotlib.pyplot as plt
plt.style.use('my_custom_stylesheet')
plt.rcParams['axes.prop_cycle'] = plt.cycler('color', ['']) # Equivalent of plt.gca().set_prop_cycle(None)

However I'm unable to return the axes.prop_cycle to return to its default. Is this possible without having to explicitly ['k, b, r, ...'] list all of the colors that I'd like to use?

Jason
  • 4,346
  • 10
  • 49
  • 75
  • I may be misunderstanding the question, but why don't you just edit the `'my_custom_stylesheet'` and replace the axes.prop_cycle in it? – ImportanceOfBeingErnest Oct 23 '18 at 00:48
  • You understand the question correctly and that's a perfectly sensible suggestion. I could do that or create a copy of the stylesheet and comment out that line but I was looking for the 'proper' to do this for my own understanding. – Jason Oct 23 '18 at 00:56
  • I would consider this to be the "proper" way of doing it, because style sheets are there for exactly this purpose. It would also have the advantage that you don't even need a single additional line in the code. Concerning the question here, is it then "I would like to know how to reset the property cycler *after* having loaded the style sheet." ? – ImportanceOfBeingErnest Oct 23 '18 at 01:00
  • Yes, sorry I could have worded the title more clearly. The reason I asked the question is because I have a commonly used stylesheet but from time to time I need to produce slightly different figures. Previously I've been creating new stylesheets (so as not to infer with previous work) on each occasion which only differ from one another by 1 or 2 parameters to save time but in the long run I never reuse those adhoc sheets because it's difficult to keep track of what I changed. So I go back and make a new copy of my 'master' template and repeat the process.This would make things more convenient. – Jason Oct 23 '18 at 01:09
  • Ok, maybe relevant in this respect: You may [compose style sheets](https://matplotlib.org/tutorials/introductory/customizing.html#composing-styles): `plt.style.use(['my_standard_stylesheet', 'my_useful_expansion_style'])`. – ImportanceOfBeingErnest Oct 23 '18 at 01:21
  • @ImportanceOfBeingErnest Thanks, that's awesome! The answer to the question I didn't know I had! – Jason Oct 23 '18 at 01:24

1 Answers1

5

If the question is how to set the rcParams["axes.prop_cycle"] to the default after having loaded a different style sheet, this would be done via

import matplotlib.pyplot as plt
plt.style.use('my_custom_stylesheet')
plt.rcParams['axes.prop_cycle'] = plt.rcParamsDefault['axes.prop_cycle']
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712