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

标签 python plot colormap

我正在使用 python 绘制一个包含 3 个子图的图形。我想将每个子图的颜色图设置为热门,我的代码如下:

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()

但是,我的情节是这样的: enter image description here

第一个不是热门色彩图,有办法解决这个问题吗?

最佳答案

当您在坐标区上绘图时,您需要在绘图之前设置全局颜色条。因此,您需要在第一个 ax.imshow() 之前调用 plt.hot()

关于python:如何为3个子图设置相同的颜色图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934193/

相关文章:

python - flask 错误处理

r - 将 x 轴标签置于分组条形图下方居中

matplotlib - 在 Mayavi 体积可视化中使用感知均匀的色彩图

matlab - 如何通过Python获取3D彩色表面?

Python matplotlib 手动颜色图

python - `asyncio.run()` 不等待协程完成

python - Theano:对稀疏矩阵的非零元素进行运算

r - 在 facet_grid ggplot : x-axis labels differ per row 上强制 x 轴标签

python - Matplotlib - 箱线图根据 log10 值计算但以对数刻度显示

python - ndarray 中最大值的索引列表