【发布时间】:2015-01-26 21:43:37
【问题描述】:
matplotlib 中是否可以自动生成多个子图?我想要自动化的过程的一个例子是:
import matplotlib.pyplot as plt
figure = plt.figure()
ax1 = figure.add_subplot(2, 3, 1)
ax2 = figure.add_subplot(2, 3, 2)
ax3 = figure.add_subplot(2, 3, 3)
ax4 = figure.add_subplot(2, 3, 4)
ax5 = figure.add_subplot(2, 3, 5)
ax6 = figure.add_subplot(2, 3, 6)
子图需要唯一的名称,因为这将允许我执行以下操作:
for ax in [ax1, ax2, ax3, ax4, ax5, ax6]:
ax.set_title("example")
非常感谢。
补充:有没有自动生成多个子图的函数?如果我需要重复上述过程 100 次怎么办?我必须将每个 ax1 都输入到 ax100 吗?
【问题讨论】:
-
自动生成,什么意思?你能说得更具体点吗?
-
要生成上述6个子图,我相信您只能通过为剩余的
title,legend etc添加更多for循环来最小化代码。
标签: python-2.7 matplotlib subplot