轴尺寸由图形尺寸和图形间距确定,可以使用设置
figure.subplots_adjust()。相反,这意味着您可以通过考虑图形间距来设置图形尺寸来设置轴尺寸:
import matplotlib.pyplot as pltdef set_size(w,h, ax=None): """ w, h: width, height in inches """ if not ax: ax=plt.gca() l = ax.figure.subplotpars.left r = ax.figure.subplotpars.right t = ax.figure.subplotpars.top b = ax.figure.subplotpars.bottom figw = float(w)/(r-l) figh = float(h)/(t-b) ax.figure.set_size_inches(figw, figh)fig, ax=plt.subplots()ax.plot([1,3,2])set_size(5,5)plt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)