【发布时间】:2012-09-04 12:59:06
【问题描述】:
我正在尝试制作一个包含 7 个子图的图。目前我正在绘制两列,一列有四个图,另一列有三个,即像这样:
我正在按以下方式构建这个情节:
#! /usr/bin/env python
import numpy as plotting
import matplotlib
from pylab import *
x = np.random.rand(20)
y = np.random.rand(20)
fig = figure(figsize=(6.5,12))
subplots_adjust(wspace=0.2,hspace=0.2)
iplot = 420
for i in range(7):
iplot += 1
ax = fig.add_subplot(iplot)
ax.plot(x,y,'ko')
ax.set_xlabel("x")
ax.set_ylabel("y")
savefig("subplots_example.png",bbox_inches='tight')
但是,对于发布,我认为这看起来有点难看——我想做的是将最后一个子图移到两列之间的中心。那么,调整最后一个子图的位置以使其居中的最佳方法是什么? IE。使前 6 个子图位于 3X2 网格中,最后一个子图位于两列之间的中心。如果可能的话,我希望能够保留for 循环,以便我可以简单地使用:
if i == 6:
# do something to reposition/centre this plot
谢谢,
亚历克斯
【问题讨论】:
-
必须是 3x2 网格吗?
标签: python matplotlib customization subplot