我想让我绘制的值与colorbar值兼容。我怎样才能做到这一点?请参阅下面的详细信息。
y1,y2,y3值为:[ - 1.7 -1.62 -1.53 -1.43 -1.32 -1.2 -1.09 -0.97 -0.85], [-1.43 -1.28 -1.09 -0.88 -0.66 -0.44 -0.21 0.03 0.27],[ - 3.65 -3.58 -3.48 -3.38 -3.27 -3.16 -3.04 -2.92 -2.8]
import matplotlib.pyplot as plt
import numpy as np
#plot
fig = plt.figure(figsize=(9.6,6), dpi=300, linewidth=3.0)
ax = fig.add_subplot(311)
y1 = y.transpose() #y should be the first data I gave out in the beginning
gradient = [ y1,y1 ]
plt.imshow(gradient, aspect='auto', cmap=plt.get_cmap('hot'))
ax.set_xticklabels(data[list[1]])
ax2 = fig.add_subplot(312)
y2 = y.transpose() #y should be the second data I gave out in the beginning
gradient = [ y2,y2 ]
plt.imshow(gradient, aspect='auto', cmap=plt.get_cmap('hot'))
ax2.set_xticklabels(data[list[5]])
ax3 = fig.add_subplot(313)
y3 = y.transpose() #y should be the third data I gave out in the beginning
gradient = [ y3,y3 ]
plt.imshow(gradient, aspect='auto', cmap=plt.get_cmap('hot'))
ax3.set_xticklabels(data[list[9]])
sm = plt.cm.ScalarMappable(cmap=plt.get_cmap('hot'),norm=plt.Normalize(-6.39,9.29))
sm._A = []
plt.colorbar(sm,ax=[ax,ax2,ax3])
#fig.set_tight_layout(True) #how can I use this? If I use this it generates a warning and the plot overlaps
plt.savefig('CuxOxi.png',dpi=300,format='png', orientation='landscape')
从图中可以看出,颜色条的范围是-6.39到9.29。每个子图的范围仅为完整颜色条范围的一小部分。我怎样才能使例如-1.62到-1.2具有颜色条中定义的颜色范围(主要是红色)
答案 0 :(得分:1)
在每个图中,您可以将vmin
和vmax
选项添加到plt.imshow
函数,以便为该图设置颜色比例最小值和最大值。您可以为每个绘图定义它们,使它们都具有相同的比例。
vmin = -6
vmax = 9
plt.imshow(gradient, aspect='auto', cmap=plt.get_cmap('hot'),vmin=vmin,vmax=vmax)