另外,如果您想简单地设置刻度线的数量,同时允许matplotlib对其进行定位(目前仅使用MaxNLocator),则有pyplot.locator_params,pyplot.locator_params(nbins=4)您可以按照以下方法在此方法中指定特定的轴,默认为两者:# To specify the number of ticks on both or any single axespyplot.locator_params(axis='y', nbins=6)pyplot.locator_params(axis='x', nbins=10)