2017-06-20 48 views
0

我有一组12个图,我想保存为一个。第一组是9段的3×3子图,第二部分是4段的2×2子图。 我试图在这两个之间添加一个子图(121),我试图使用图(1)和图(2),但都没有遇到我将这两个图像保存为一个大图像。有没有一个简单的方法来做到这一点?Python绘制两个子图

plt.subplot(331) 
plt.imshow(getpoly(seg1),origin="lower") 
plt.subplot(332) 
plt.imshow(getpoly(seg2),origin="lower") 
plt.subplot(333) 
plt.imshow(getpoly(seg3),origin="lower") 
plt.subplot(334) 
plt.imshow(getpoly(seg4),origin="lower") 
plt.subplot(335) 
plt.imshow(getpoly(seg5),origin="lower") 
plt.subplot(336) 
plt.imshow(getpoly(seg6),origin="lower") 
plt.subplot(337) 
plt.imshow(getpoly(seg7),origin="lower") 
plt.subplot(338) 
plt.imshow(getpoly(seg8),origin="lower") 
plt.subplot(339) 
plt.imshow(getpoly(seg9),origin="lower") 


plt.subplot(221) 
plt.imshow(h1,origin="lower") 
plt.colorbar() 
plt.subplot(222) 
plt.imshow(h2,origin="lower") 
plt.colorbar() 
plt.subplot(223) 
plt.imshow(getpoly(h2),origin="lower") 
plt.colorbar() 
plt.subplot(224) 
plt.imshow(h1-getpoly(h2),origin="lower") 
plt.colorbar() 
+0

3×2×2 + = 9 + 4 = 13,你会如何有12个次要情节呢? – ImportanceOfBeingErnest

回答

2

你可能会想,如图here使用gridspecGridSpecFromSubplotSpec

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 

gs = gridspec.GridSpec(1, 2) 
gs0 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs[0]) 
gs1 = gridspec.GridSpecFromSubplotSpec(2, 2, subplot_spec=gs[1]) 

fig = plt.figure() 

for i in range(9): 
    ax = fig.add_subplot(gs0[i//3, i%3]) 
    ax.imshow(np.random.rand(4,4)) 
    ax.set_xticks([]); ax.set_yticks([]) 

for i in range(4): 
    ax = fig.add_subplot(gs1[i//2, i%2]) 
    ax.imshow(np.random.rand(4,4)) 
    ax.set_xticks([]); ax.set_yticks([]) 

plt.show() 

enter image description here

+0

谢谢,这正是我需要的! – Coolcrab

+0

还有一个问题,我在右边的四个图像中有颜色条,两个最右边的图像与左边的颜色条重叠。有什么方法可以轻松修复这个间距? – Coolcrab

+0

我不知道你的意思。我想你明白评论部分并不是要问一个新问题。你有两个选择:1.编辑你的问题,包括你有问题的代码和不希望的输出的图像,或者2.提出一个新的问题。 – ImportanceOfBeingErnest