I want to plot a couple of figures with several lines. Each line is asocciated with certain parameter (and a corresponding color) and i want to put a colorbar that shows the corresponding range of the parameter.
I found this question but in my case there is more than one plot ...
Here is an example code
import matplotlib.pyplot as plt
import numpy as np
my_map = plt.cm.spectral
c = np.arange(10)
colors = [my_map(i) for i in np.linspace(0, 1, len(c))]
sm = plt.cm.ScalarMappable(cmap=my_map,norm=plt.Normalize(np.min(c),np.max(c)))
sm._A = []
fig = plt.figure()
ax1 = fig.add_subplot(211)
for i in range(len(c)):
c0 = c[i]
ax1.plot(c,c+c0,color=colors[i])
ax2 = fig.add_subplot(212)
for i in range(len(c)):
c0 = c[i]
ax2.plot(c,c+c0,color=colors[i])
fig.colorbar(sm)
plt.show()
plt.close()
I'm almost there but i need to move the colorbar (create an axis ? )
Thanks