我有一个值的空间域,在一天中以固定的间隔输出。我正在用contourf
绘制,我想在一天的数据过程中执行以下操作:
例如:
data = np.random.uniform(0, 5, size=(24,30,30))
data[3,:,:]=np.random.uniform(1,3,size=(30,30)) # example of bad plot
fgsize=(12,4)
numrecs = np.size(data,axis=0)
cbar_min = np.min(data)
cbar_max = np.max(data)
cbarlabels = np.linspace(np.floor(cbar_min), np.ceil(cbar_max), num=5, endpoint=True)
for tt in range(0, numrecs):
plt.figure(figsize=fgsize, dpi=80)
plt.title('this is a title')
plt.contourf(data[tt, :, :], 35, vmin=cbar_min, vmax=cbar_max, cmap='coolwarm')
cbar =plt.colorbar()
cbar.set_ticks(cbarlabels)
cbar.set_ticklabels(cbarlabels)
cbar.set_label('my data has units')
plt.show()
plt.close()
这是一个bad plot的例子。颜色看起来是有限的,但是颜色栏改变了它的颜色/标签限制。我怎么解决这个问题?在
下面是一个good plot的示例。在
事实证明,在为colormap设置级别时,contourf有点棘手,请参见this answer。通过对轮廓进行法线化,可以获得适当的限制和颜色,如下所示:
相关问题 更多 >
编程相关推荐