您想了解plt.xlim
个函数及其邻近函数.这会导致X轴具有you指定的限制(最小值、最大值).否则,Matplotlib将根据您try 绘制的值为您做出决定.
y = 1 / np.arange(0.1,3,0.1)
plt.plot(y)
plt.xlim(0, 3) # minimum 0, maximum 3
plt.show()
绘图仅使用Y值,因此X值会自动 Select 为1、2、3、...与您提供的每个Y值配对.
如果您也想确定X,可以这样做:
x = np.arange(0.1,3,0.1)
y = 1/x
plt.plot(x, y)
plt.xticks([0,1,2,3]) # ticks at those positions, if you don't like the automatic ones
plt.show()