Reputation: 49
I have two arrays x and y and I would like to plot the r2 value (r2.shape=(1,N)) of those two arrays at the bottom of a figure with color using matplotlib library in python. like the example below
Upvotes: 0
Views: 1434
Reputation: 1835
You could do it this way:
N = 100
r2 = np.random.uniform(0,1,(1,N))
r2 = r2.T
fig, ax = plt.subplots()
ax.plot(np.arange(r2.shape[0]), r2[:,0])
my_cmap = plt.get_cmap("viridis")
rescale = lambda y: (y - np.min(y)) / (np.max(y) - np.min(y))
ax.bar(np.arange(len(r2)), height=0.05, width=1, bottom=0, color=my_cmap(rescale(r2[:,0])))
plt.show()
Upvotes: 3