简体   繁体   English

更改y轴的数量计数(Python,matplotlib.pyplot)

[英]Changing the count of numbers of the y-axis (Python, matplotlib.pyplot)

I just have a small problem with pyplot. 我只是pyplot有一个小问题。

I am plotting my data in a way like: 我正在以如下方式绘制数据:

import matplotlib.pyplot as plt

plt.subplot(i,3,j)
plt.plot(xy.data)
plt.show()

With several subplots. 有几个子图。 Now my problem is: When I have many subplots, the plots become very small and espacially flat. 现在我的问题是:当我有许多子图时,地块会变得非常小,尤其是平坦的。 So the numbers that are on my y-axis become impossible to read, cause they overlap each other. 因此,我的y轴上的数字变得无法读取,因为它们相互重叠。

Is it somehow easily possible to change the count of the numbers to something like 3? 是否可以轻松地将数字的计数更改为3? So I just have the maximum, zero and the minimum? 所以我只有最大值,零和最小值? But not the minimum of my function, I would rather keep the minimum (and max) that is currently there. 但不是我函数的最小值,我宁愿保留当前存在的最小值(和最大值)。 So I just would like to let every step inbetween the current min, 0 and max away. 因此,我只想让当前的最小值,0和最大值之间的每一步消失。

Thank You all, have a nice day. 谢谢大家,祝你有美好的一天。

from matplotlib.ticker import MaxNLocator
plt.gca().yaxis.set_major_locator(MaxNLocator(3))

MaxNLocator sets the amount of ticks, and with the plt.gca().yaxis you make this happen on the y-axis. MaxNLocator设置刻度的数量,并使用plt.gca().yaxis使其在y轴上发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM