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?

6
  • 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? Commented Oct 23, 2018 at 0: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. Commented Oct 23, 2018 at 0: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." ? Commented Oct 23, 2018 at 1: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. Commented Oct 23, 2018 at 1:09
  • Ok, maybe relevant in this respect: You may compose style sheets: plt.style.use(['my_standard_stylesheet', 'my_useful_expansion_style']). Commented Oct 23, 2018 at 1:21

1 Answer 1

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']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.