matplotlib.axes.Axes
类 中使用 autoscale
方法的 matplotlib 相关内容。
使用功能API,您可以应用紧密的x轴。plt.autoscale(enable=True, axis='x', tight=True)
ax = plt.gca() # only to illustrate what `ax` is
ax.autoscale(enable=True, axis='x', tight=True)
为了完整性,axis
参数可以取 'x'
、'y'
或 'both'
,其中默认值为 'both'
。
autoscale
实际上是Axes
类的一个方法。 - Wisperwindaxis = 'y'
,但没有任何变化。 - Steven C. Howell我只需在那些我知道会想让我的xlims贴着数据的脚本开头放入以下内容:
import matplotlib.pyplot as plt
plt.rcParams['axes.xmargin'] = 0
plt.xlim(lower_limit, upper_limit)
虽然接受的答案是有效的,而且我曾经使用过一段时间,但我转而采用这种策略,因为我每个脚本只需要记住一次。