2017-04-07 43 views
0

我做了以下可视化。 enter image description here我很想知道如何根据另外两个(它们共享x轴)来调整第三个子区域的大小。 给出here的属性没有多大帮助,我在SO上找到的示例似乎也是针对与我的不同情况。任何人都可以帮忙吗?用调色板调整子图形

+0

请张贴的代码示例展示了如何创建地块。 (保持简短 - 不需要使用数据填充子图),除非这是造成问题的原因。) – kazemakase

回答

0

一个简单的方法是添加另外两个颜色条,但使它们不可见。

import matplotlib.pyplot as plt 

fig, (ax,ax2,ax3) = plt.subplots(3,1, sharex=True) 
ax.plot([1,3,5],[1,2,5]) 
ax2.plot([3,5,9],[4,2,2]) 
ax3.plot([5,7,12],[1,5,3]) 

sm = plt.cm.ScalarMappable() 
sm.set_array([]) 
fig.colorbar(sm, ax=ax3) 

# add two more colorbars, but make them invisible 
fig.colorbar(sm, ax=ax2).ax.set_visible(False) 
fig.colorbar(sm, ax=ax).ax.set_visible(False) 

plt.subplots_adjust(right=1) 
plt.show() 

enter image description here