Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.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子批次中的NTICK_Python_Matplotlib - Fatal编程技术网

Python 更改matplotlib子批次中的NTICK

Python 更改matplotlib子批次中的NTICK,python,matplotlib,Python,Matplotlib,在本例中,为什么x轴和y轴上的记号数没有减少到3 import numpy as np import matplotlib.pyplot as plt fig,ax=plt.subplots(nrows=4,ncols=3) for n in range(0,4): for f in range(0,3): ax[n,f].plot(range(10), range(10,20)) ax[n,f].locator_params(axis='x', nti

在本例中,为什么x轴和y轴上的记号数没有减少到3

import numpy as np
import matplotlib.pyplot as plt

fig,ax=plt.subplots(nrows=4,ncols=3)
for n in range(0,4):
    for f in range(0,3):
        ax[n,f].plot(range(10), range(10,20))
        ax[n,f].locator_params(axis='x', nticks=3)
        ax[n,f].locator_params(axis='y', nticks=3)

fig.savefig('not_3_ticks.png')

我只剩下下图:

定位器参数(axis='x',nticks=3)无法按预期工作的原因是
nticks
不是使用中的
matplotlib.ticker.AutoLocator
的有效参数

从:

通常,人们可能希望减少最大数量 在打印小刻度时使用紧边界 子地块,例如:

ax.locator_params(tight=True, nbins=4)

因此,将
nticks
替换为
nbins

定位器参数(axis='x',nticks=3)
不能按预期工作的原因是
nticks
不是使用中的
matplotlib.ticker.AutoLocator
的有效参数

从:

通常,人们可能希望减少最大数量 在打印小刻度时使用紧边界 子地块,例如:

ax.locator_params(tight=True, nbins=4)
因此,将
nticks
替换为
nbins

这同样有效:

import numpy as np
import matplotlib.pyplot as plt

fig,ax = plt.subplots(nrows=4,ncols=3)

for n in range(0,4):
    for f in range(0,3):
        ax[n,f].plot(range(10), range(10,20))
        ax[n,f].xaxis.set_major_locator(plt.MaxNLocator(3))
        ax[n,f].yaxis.set_major_locator(plt.MaxNLocator(3))

plt.plot()
plt.show()
fig.savefig('yes_3_ticks.png')

这也适用于:

import numpy as np
import matplotlib.pyplot as plt

fig,ax = plt.subplots(nrows=4,ncols=3)

for n in range(0,4):
    for f in range(0,3):
        ax[n,f].plot(range(10), range(10,20))
        ax[n,f].xaxis.set_major_locator(plt.MaxNLocator(3))
        ax[n,f].yaxis.set_major_locator(plt.MaxNLocator(3))

plt.plot()
plt.show()
fig.savefig('yes_3_ticks.png')

不是matplotlib.ticker.AutoLocator的有效参数——一个技术要点:我对文档的理解是任何关键字参数都是有效参数。@7stud当然,任何关键字参数都可以使用,例如,
ax.locator\u params(state\u of_mind=“excited”)
在python正确处理的意义上是有效的。但是这里的“valid”意味着它实际上被传递到的函数使用。不是matplotlib.ticker.AutoLocator的有效参数——一个技术要点:我对文档的理解是任何关键字参数都是有效参数。@7stud当然,任何关键字参数都可以使用,例如,
ax.locator\u参数(state\u of\u mind=“excited”)
在python正确处理的意义上是有效的。但此处的“有效”表示它实际上被传递到的函数使用。请注意,如果省略轴arg,“两者”是轴arg的默认值,因此可以用一行设置两个轴。请注意,如果省略轴arg,“两者”是轴arg的默认值,因此可以用一行设置两个轴。