Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在matplotlib中的完全自定义位置中放置小刻度?_Python_Matplotlib_Plot_Customization_Axis Labels - Fatal编程技术网

Python 如何在matplotlib中的完全自定义位置中放置小刻度?

Python 如何在matplotlib中的完全自定义位置中放置小刻度?,python,matplotlib,plot,customization,axis-labels,Python,Matplotlib,Plot,Customization,Axis Labels,假设我想在自定义位置向x轴添加小刻度,该位置相当于主刻度的此命令:plt.xticks([1,2,3]) 我试过: import matplotlib.pyplot as plt x = [1,2,3] y = [1,4,9] plt.scatter(x,y) ax = plt.gca() ax.xaxis.set_minor_locator([1.1, 1.9, 2.5]) 但这会引发一个错误,因为最后一个命令可能需要一个ticker对象,而不是参数中的列表。有什么类似于python的方法吗

假设我想在自定义位置向x轴添加小刻度,该位置相当于主刻度的此命令:
plt.xticks([1,2,3])

我试过:

import matplotlib.pyplot as plt
x = [1,2,3]
y = [1,4,9]
plt.scatter(x,y)
ax = plt.gca()
ax.xaxis.set_minor_locator([1.1, 1.9, 2.5])

但这会引发一个错误,因为最后一个命令可能需要一个ticker对象,而不是参数中的列表。有什么类似于python的方法吗?

您只需添加以下行,然后打开
minor
标志以
True

ax.set_xticks([1.1, 1.9, 2.5], minor=True)