change each line color as a rainbow python

Solutions on MaxInterview for change each line color as a rainbow python by the best coders in the world

showing results for - "change each line color as a rainbow python"
Till
07 Jan 2021
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