【发布时间】:2019-10-15 07:06:04
【问题描述】:
我想制作一个具有 2x2 外部布局和这些 2x3 布局中的每一个的地块。我设法使用 gridSpec 让一切正常工作,但我似乎无法为每个 subplotSpec 分配一个标题(有 2x2 subplotSpec)。
Row titles for matplotlib subplot 这原则上应该给我解决方案,但我想知道是否有办法使用gridSpec而不是隐藏白框来实现这一点。
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
netdict = ["chain","V"]
sigdict = ["no","with"]
fig = plt.figure(figsize=(10, 8))
outer = gridspec.GridSpec(2, 2, wspace=0.3, hspace=0.3) # make a 2x2 outer frame
for ni, networktype in enumerate(netdict):
for si, sigtype in enumerate(sigdict):
fig.add_subplot(outer[ni*2+si])
plt.title(networktype+ " " + sigtype) # title for each outer frame
plt._frameon=False # this should make the unnecessary white frame go away
inner = gridspec.GridSpecFromSubplotSpec(2, 3, # make 2x3 inner frame
subplot_spec=outer[ni*2+si], wspace=0.4, hspace=0.4)
for ti,tau in enumerate([5.5,12.5]):
for u, xy_delay in enumerate([0,tau,2*tau]):
ax = plt.Subplot(fig, inner[ti*3+u])
ax.plot(np.sin(np.linspace(0,10,0.5))
ax.set(title=r"$\tau_u={}$".format(xy_delay))
fig.add_subplot(ax)
plt.show()
【问题讨论】:
-
必须手工放置。
gridspec.suptitle是 matplotlib 正在考虑的事情,但还没有完成。
标签: python matplotlib