csiz
csiz

Reputation: 5190

How do I switch to the new color map in matplotlib 1.5?

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...

Upvotes: 1

Views: 562

Answers (1)

Paul H
Paul H

Reputation: 68176

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)

Upvotes: 2

Related Questions