我想在 A4 圖中放置幾個??子圖。
使用此代碼,我有不需要的白色間隙。我怎樣才能洗掉它們(見圖)。謝謝
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
gs1 = gridspec.GridSpec(8, 2)
gs1.update(wspace=0.025, hspace=0.05) # set the spacing between axes.
plt.figure(figsize=(11.69,8.27)) # for landscape
colors=['c','m','y','k','b','g','r','w']
for i in range(16):
ax = plt.subplot(gs1[i])
ax.set_xticklabels([])
ax.set_yticklabels([])
ax.tick_params(left = False, bottom = False)
ax.set_facecolor(colors[i%8])
plt.savefig("toto.png")

uj5u.com熱心網友回復:
import matplotlib.pyplot as plt
gridspec_kw = {'wspace':0.025, 'hspace':0.05}
fig, ax = plt.subplots(8, 2,
figsize=(11.69,8.27),
gridspec_kw=gridspec_kw,
layout="constrained")
colors = ['c', 'm', 'y', 'k', 'b', 'g', 'r', 'w']
for i in range(8):
# left subplot
ax[i, 0].set_xticklabels([])
ax[i, 0].set_yticklabels([])
ax[i, 0].tick_params(left=False, bottom=False)
ax[i, 0].set_facecolor(colors[(2*i)%8])
# right subplot
ax[i, 1].set_xticklabels([])
ax[i, 1].set_yticklabels([])
ax[i, 1].tick_params(left=False, bottom=False)
ax[i, 1].set_facecolor(colors[(2*i)%8 1])
plt.savefig("toto_stack_overflow.png")
uj5u.com熱心網友回復:
還有另一種不涉及重組/拆分情節的方法:
fig = plt.figure(figsize=(11.69,8.27)) # for landscape
fig.subplots_adjust(bottom=0, top=1, left=0, right=1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/536265.html
