自定义 Matplotlib 子图
Customising Matplotlib Subplots
我一直觉得 matplotlib 子图令人困惑,所以我想知道是否有人可以展示如何生成以下子图排列:
Subplot Image
提前致谢。
您可以使用 plt.GridSpec 轻松创建不同大小的子图。
cols = 5 #number of columns in the grid
s = 2 #width of top right subplot in #cells
w = 1 #spacing between subplot columns
fig = plt.figure()
gs = plt.GridSpec(2, cols, figure=fig, wspace=w)
ax1 = fig.add_subplot(gs[0, :-s])
ax2 = fig.add_subplot(gs[0, -s:])
ax3 = fig.add_subplot(gs[1, :-s])
@Marc 的回答很好,但也许更容易和更灵活的是:
fig, axs = plt.subplots(2, 2, gridspec_kw={'width_ratios':[2, 1]})
# if you really don't want 4 axes:
fig.delaxes(axs[1, 1])
我一直觉得 matplotlib 子图令人困惑,所以我想知道是否有人可以展示如何生成以下子图排列: Subplot Image
提前致谢。
您可以使用 plt.GridSpec 轻松创建不同大小的子图。
cols = 5 #number of columns in the grid
s = 2 #width of top right subplot in #cells
w = 1 #spacing between subplot columns
fig = plt.figure()
gs = plt.GridSpec(2, cols, figure=fig, wspace=w)
ax1 = fig.add_subplot(gs[0, :-s])
ax2 = fig.add_subplot(gs[0, -s:])
ax3 = fig.add_subplot(gs[1, :-s])
@Marc 的回答很好,但也许更容易和更灵活的是:
fig, axs = plt.subplots(2, 2, gridspec_kw={'width_ratios':[2, 1]})
# if you really don't want 4 axes:
fig.delaxes(axs[1, 1])