简体   繁体   English

Python:如何为3个子图设置相同的颜色图

[英]python: how to set the same colormap for 3 subplots

I am using python to draw a figure with 3 subplots. 我正在使用python绘制具有3个子图的图形。 I want to set the colormap to be hot for each subplot and my code is like: 我想将每个子图的色图设置为热色,我的代码如下:

fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(20,15))
count = 0
for ax in axes.flat:
    count += 1
    if count == 1:
        im = ax.imshow(data_in_array, interpolation='nearest',vmin=0, vmax=150)
        ax.set_xticks(range(24))
        ax.set_xticklabels(('6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','0','1','2','3','4','5'),fontsize=15)
        ax.set_yticks(range(8))
        ax.set_yticklabels(('Belltown', 'Downtown', 'Industrial District', 'Wallingford', 'University District', 'Capitol Hill', 'Lakecity','Ballard'),fontsize=15)
        ax.set_title('arriving hours of travel survey',fontsize=15)
        plt.hot()

    if count == 2:
        im = ax.imshow(data_out_array, interpolation='nearest',vmin=0, vmax=150)
        ax.set_xticks(range(24))
        ax.set_xticklabels(('6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','0','1','2','3','4','5'),fontsize=15)
        ax.set_yticks(range(8))
        ax.set_yticklabels(('Belltown', 'Downtown', 'Industrial District', 'Wallingford', 'University District', 'Capitol Hill', 'Lakecity','Ballard'),fontsize=15)
        ax.set_title('leaving hours of travel survey',fontsize=15)
        plt.hot()

    if count == 3:
        im = ax.imshow(data_stay_array, interpolation='nearest',vmin=0, vmax=150)
        ax.set_xticks(range(24))
        ax.set_xticklabels(('6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','0','1','2','3','4','5'),fontsize=15)
        ax.set_yticks(range(8))
        ax.set_yticklabels(('Belltown', 'Downtown', 'Industrial District', 'Wallingford', 'University District', 'Capitol Hill', 'Lakecity','Ballard'),fontsize=15)
        ax.set_title('stay hours of travel survey',fontsize=15)
        plt.hot()   


fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.75, 0.1, 0.03, 0.8])
fig.colorbar(im, cax=cbar_ax)
plt.show()

However, my plot is like: 但是,我的情节是这样的: 在此处输入图片说明

The first one is not the hot colormap, any idea to fix that? 第一个不是热门的色彩图,有什么办法解决吗?

When you are plotting on the axes, you need to set the global colorbar before plotting. 在轴上绘制时,需要在绘制之前设置全局色条。 Hence, you need to have a plt.hot() call before the first ax.imshow() . 因此,您需要在第一个plt.hot()之前调用ax.imshow()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM