1 回答

TA貢獻1943條經驗 獲得超7個贊
我認為,當您使用 時bbox_inches="tight",您會縮短圖形以刪除空白,并且不會延長軸。
對我來說使用constrained_layout = true或plt.tight_layout()在乳膠下工作。
import matplotlib.pyplot as plt
xwidth = 418.25555 / 72 # conversion from in to pt
ywidth = 300 / 72 # conversion from in to pt
fig,ax = plt.subplots(figsize=[xwidth, ywidth], constrained_layout = True)
ax.plot([1,2,3],[1,2,3])
ax.set_ylabel("Y-label")
ax.set_xlabel("X-label")
fig.savefig("test.pdf")
或者
import matplotlib.pyplot as plt
xwidth = 418.25555 / 72 # conversion from in to pt
ywidth = 300 / 72 # conversion from in to pt
fig,ax = plt.subplots(figsize=[xwidth, ywidth])
ax.plot([1,2,3],[1,2,3])
ax.set_ylabel("Y-label")
ax.set_xlabel("X-label")
plt.tight_layout()
fig.savefig("test.pdf")
添加回答
舉報