从matplotlib子图中检索完整的几何网格信息

时间:2016-09-27 08:25:57

标签: python matplotlib

考虑

import numpy as np
import matplotlib.pyplot as plt

data = np.zeros((3, 3))

fig = plt.figure()

ax1 = plt.subplot(131)
ax2 = plt.subplot(132)
ax3 = plt.subplot(133)
axes = [ax1, ax2, ax3]

for ax in axes:
    im = ax.imshow(data)

结果数字fig有3个AxesSubplot个孩子,每个子图一个。它们的几何形状

for child in fig.get_children():
    try:
        print(child.get_geometry())
    except AttributeError:
        pass
(1, 3, 1)
(1, 3, 2)
(1, 3, 3)

有道理。

现在让我们添加一些颜色条:

for ax in axes:
    fig.colorbar(im, ax=ax, orientation='horizontal')

现在将几何图形报告为

(2, 1, 1)
(2, 1, 1)
(2, 1, 1)
(1, 3, 2)
(1, 3, 2)
(1, 3, 2)
嗯,怎么理解那些?

0 个答案:

没有答案