Python 更改matplotlib子批次中的NTICK
在本例中,为什么x轴和y轴上的记号数没有减少到3Python 更改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
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的默认值,因此可以用一行设置两个轴。