1

I want to write a line to switch all my plots to the new color map (viridis), how do I do that?

There's a lot of information on the new available colors http://matplotlib.org/users/colormaps.html, there's information on how to pick a style with the style.use("ggplot") http://matplotlib.org/users/style_sheets.html, and there's a page saying that the new color map is changing http://matplotlib.org/style_changes.html#. On none of those do they say how to actually switch to a different colormap...

csiz
  • 4,742
  • 9
  • 33
  • 46
  • What do you mean with *write a line to..*? What kind of plots? If you always used the default colormap without specifying e.g. `cmap=..` in your code, you could simply set the default colormap in your `matplotlibrc` file. http://stackoverflow.com/questions/33185037/how-to-set-default-colormap-in-matplotlib – Bart Oct 18 '16 at 19:20
  • I mean I expected to be able to do `styles.use("viridis")` but it's not in `styles.available`. I wanted to apply the theme to all types of plots. Editing the matplotlibrc seems like the way to go :( – csiz Oct 18 '16 at 19:34
  • Ok, clear. Never used `styles` before, so no idea if that's possible – Bart Oct 18 '16 at 19:36

1 Answers1

2

In matplotlib, the "styles" control much, much more than just the colormap.

To configure one aspect of the style on the fly, use:

import matplotlib
matplotlib.rcParams['image.cmap'] = 'viridis'

In the forthcoming v2.0 release of matplotlib, viridis will be the default colormap and this won't be necessary. Lots of other stylistic changes will be in place as well. You can look at those here:

http://matplotlib.org/devdocs/gallery.html

To look at the available styles, inspect the available list:

from matplotlib import pyplot
pyplot.style.available

For the new default color cycle, you'd do:

from cycler import cycler
colors = [
    '#1f77b4', '#ff7f0e', '#2ca02c',
    '#d62728', '#9467bd', '#8c564b',
    '#e377c2', '#7f7f7f', '#bcbd22',
    '#17becf'
]
matplotlib.rcParams['axes.prop_cycle'] = cycler('color', colors)
Paul H
  • 65,268
  • 20
  • 159
  • 136
  • 1
    What about setting the default color cycle (for line plots) to whatever matplotlib 2.0 is going to use? – csiz Oct 18 '16 at 19:43
  • Yay, this is soothing to my eyes. Thanks! (btw edit the param to axes.prop_cycle) – csiz Oct 18 '16 at 19:56
  • Last line in example should read: `matplotlib.rcParams['axes.prop_cycle'] = cycler('color', colors)` (prop_cycle in stead of prob_cycle) – Joma Aug 08 '18 at 09:47