matplotlib三个图的网格排列

时间:2017-01-25 15:14:39

标签: python matplotlib

我想以下列安排绘制3个地块

------------------------ 
| ax1                  | 
------------------------
---------------  ------- 
|   ax2       | | ax3  |
---------------- -------

所以ax2应占空间的6/10左右,ax3应占用4/10的空间。

这是我的想法,但它不起作用:

f, ax = plt.subplots(2,10, figsize=(10,4))
ax1 = plt.subplot2grid((2,2), (0,0), colspan=10)
ax2 = plt.subplot2grid((2,2), (1, 0), colspan=6)
ax3 = plt.subplot2grid((2,2), (1, 1), colspan=4)

2 个答案:

答案 0 :(得分:2)

我认为这应该能满足您的需求:

import matplotlib.pyplot as plt

ax1 = plt.subplot2grid((3,3), (0,0), colspan=3)
ax2 = plt.subplot2grid((3,3), (1,0), colspan=2)
ax3 = plt.subplot2grid((3,3), (1, 2), colspan=1)

plt.show()

我想弄清楚为什么你写的东西不起作用.. brb

答案 1 :(得分:2)

你几乎就在那里,但我认为你需要将所有内容相乘,以便为所有行和列提供足够的子图。尝试:

ax1 = plt.subplot2grid((10,10), (0,0), colspan=10, rowspan=5)
ax2 = plt.subplot2grid((10,10), (5,0), colspan=6, rowspan=5)
ax3 = plt.subplot2grid((10,10), (5,6), colspan=4, rowspan=5)

输出:

enter image description here

(你可能想要使用轴刻度和填充来玩一下......)

相关问题