Matplotlib set_color_cycle versus set_prop_cycle : <p>One of my favorite things to do in Matplotlib is to set the color-cycle to match some colormap, in order to produce line-plots that have a nice progression of colors across the lines. Like this one:</p>

<p><a href="https://i.stack.imgur.com/vaoiJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vaoiJ.png" alt="enter image description here"></a></p>

<p>Previously, this was one line of code using <code>set_color_cycle</code>:</p>

<pre><code>ax.set_color_cycle([plt.cm.spectral(i) for i in np.linspace(0, 1, num_lines)])
</code></pre>

<p>But, recently I see a warning:</p>

<pre><code>MatplotlibDeprecationWarning: 
The set_color_cycle attribute was deprecated in version 1.5. 
Use set_prop_cycle instead.
</code></pre>

<p>Using <code>set_prop_cycle</code>, I can achieve the same result, but I need to <code>import cycler</code>, and the syntax is less compact:</p>

<pre><code>from cycler import cycler
colors = [plt.cm.spectral(i) for i in np.linspace(0, 1, num_lines)]
ax.set_prop_cycle(cycler('color', colors))
</code></pre>

<p>So, my questions are: </p>

<p>Am I using <code>set_prop_cycle</code> correctly? (and in the most efficient way?)</p>

<p>Is there an easier way to set the color-cycle to a colormap? In other words, is there some mythical function like this? </p>

<pre><code>ax.set_colorcycle_to_colormap('jet', nlines=30)
</code></pre>

<p>Here is the code for the complete example:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt

ax = plt.subplot(111)
num_lines = 30

colors = [plt.cm.spectral(i) for i in np.linspace(0, 1, num_lines)]

# old way: 
ax.set_color_cycle(colors)

# new way:
from cycler import cycler
ax.set_prop_cycle(cycler('color', colors))

for n in range(num_lines):
    x = np.linspace(0,10,500)
    y = np.sin(x)+n
    ax.plot(x, y, lw=3)

plt.show()
</code></pre>
