Setting colormaps for subsequent plots

When looking for documentation on how to set colormaps, I usually find the following ways to set a colormap

matplotlib.pyplot.copper()
matplotlib.pyplot.set_cmap(matplotlib.colormap.copper)
matplotlib.cm.copper()
matplotlib.cm.set_cmap(matplotlib.colormap.copper)

The latter of these ways is documented in the API but I am told

matplotlib.cm.set_cmap(cm.copper)
AttributeError: 'module' object has no attribute 'set_cmap'

Whatsoever, a colormap can be shown with

matplotlib.cm.get_cmap().name

However, I only could find successful examples on changing the colormap for imshow, but I am interested in changing the colormap for subsequent plots like this

# FIXME Set colormap

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(num=1)
fig.clf()
ax = plt.subplot(111)
ax.hold(True)

N=10
for i in np.arange(N):
    ax.plot(np.arange(10), (i+1)*np.arange(10), label=repr(i))

This defaults to hsv (right?) but how can it be changed?

Author: Fantashit

1 thought on “Setting colormaps for subsequent plots

  1. This type of question is much better handled on the Matplotlib-users mailing list, so I am going to close the issue. Your questions indicate several possible points of confusion that other users on the list likely would be able to clarify quickly. For example, it sounds like you want a color map to be used to determine the color of each of a set of lines created with plot(); but plot() does not use color mapping at all, so you have to set the colors explicitly, like this:

    cmap = cm.get_cmap('copper')
    N = 10
    for i in range(10):
        c = cmap(float(i)/(N-1))
        plot(np.arange(10), (i+1) * np.arange(10), color=c, label=repr(i))
    

Comments are closed.