我想創建一個沒有中間空間的圖的網格。防止GridSpec子圖分離隨圖大小變化
這將是這個樣子:
代碼1
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
fig = plt.figure()
gs = GridSpec(2, 2, wspace=0.0, hspace=0.0)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, 0])
ax4 = fig.add_subplot(gs[1, 1])
fig.show()
然而,當我添加數據的次要情節之間的間距是依賴於數字的尺寸。 (這可通過改變()由fig.show打開窗口的尺寸可以看出)
作爲一個例子:
代碼2
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
import numpy as np
fig = plt.figure()
gs = GridSpec(2, 2, wspace=0.0, hspace=0.0)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, 0])
ax4 = fig.add_subplot(gs[1, 1])
for axis in [ax1, ax2, ax3, ax4]:
axis.imshow(np.random.random((10,10)))
fig.show()
所以,優選仍然使用GridSpec,是否有可能強迫這些地塊保持在一起?
我能想到的唯一的另一種選擇是訪問圖的大小並在plt.figure(figsize=(##,##))
中使用這些尺寸,但我似乎無法訪問這些數字。
注意:圖的數量會隨着高/寬比例而變化。 (例如GridSpec(2, 3, width_ratios=[10,10,1], wspace=0.0, hspace=0.0)
,我將使用最後一列來保存用於所有圖的顏色條。)
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 〜 Python的2.7.10,Matplotlib 1.4.3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
這是我調查過的東西,但imshow有點奇怪:似乎創建的東西是一個固定大小的圖像,這似乎會導致問題。 – Haydon