第一个是设置坐标轴的范围,第二个是设置精度及精度的范围:
程序:
import matplotlib.pyplot as plt import numpy as np ax = plt.gca() ax.set_xlim(-10,10) ax.set_ylim(-10,10) #网格 plt.grid(linestyle='-.') #linestyle = ls my_x1 = np.arange(-5,5,0.5) plt.xticks(my_x1) plt.show()
结果: