iterate colors matplotlib

Solutions on MaxInterview for iterate colors matplotlib by the best coders in the world

showing results for - "iterate colors matplotlib"
Emily
06 Oct 2018
1from matplotlib.pyplot import cm
2import numpy as np
3
4#variable n below should be number of curves to plot
5
6#version 1:
7
8color=cm.rainbow(np.linspace(0,1,n))
9for i,c in zip(range(n),color):
10   plt.plot(x, y,c=c)
11
12#or version 2:
13
14color=iter(cm.rainbow(np.linspace(0,1,n)))
15for i in range(n):
16   c=next(color)
17   plt.plot(x, y,c=c)
18