0

Below, you can see two barplots I've superimposed in order to better see the contrast. Both barplots were generated using identical code (different data, but this is unimportant) in two simultaneously opened Jupyter Notebooks. The code for both calls 'C3' as the color, but as you can clearly see, this displays differently in both notebooks. This is the case with both the inline and the plt.savefig versions of the images. I have also tried other colors such as 'C0' and get similar slight differences.

Any ideas what might be causing this and how I might remedy it? Thanking you all in advance.

enter image description here

cjstevens
  • 131
  • 7
  • Update: It seems this problem is happening only with the 'C0' - 'C9' color codes. If I call the same RGB code, e.g. (0.8, 0.0, 0.0) it displays the same in both notebooks. So it seems that for a reason I can't find, the two notebooks are cycling through different palettes when I call a 'C-' color code. – cjstevens Aug 11 '21 at 12:56
  • Need more information. Do both notebooks use the same kernel? Same version of matplotlib? Same rc file? – Diziet Asahi Aug 11 '21 at 20:57

1 Answers1

1

Per the color documentation the CN syntax is used to index into the current color cycler. Since RGB codes work and CN doesn't, it leads me to the conclusion that somehow the different notebooks are using different color cycles. Try the following snippet in each notebook and see if it gives you a different answer:

import matplotlib as mpl
print(mpl.rcParams["axes.prop_cycle"])

I think it's likely that somewhere in one of the notebooks there's been a call to set_prop_cycle() that has somehow changed the cycler that is being used. Also check out this post for more info on selecting the colors via the cycler.

The short answer would be to avoid the 'CN' notation.

Tom Johnson
  • 1,793
  • 1
  • 13
  • 31
  • Thanks a mil Tom. Yes, I had already switched to RGBA codes as a result of this mismatch and won't be going back to 'CN' notation, but I was still curious to get to the bottom of the problem. You have helped me do that; one of the notebooks does indeed contain a call to set_prop_cycle()... the pitfalls of imitating code one does not fully understand! – cjstevens Aug 11 '21 at 22:16