简体   繁体   English

有没有办法在 python (Matplotlib)中设置 y 轴的限制?

[英]Is there a way to set the limits on the y axis in python (Matplotlib)?

I am new to Python (v 3.7) and currently working on preprocessing pupil data.我是 Python (v 3.7) 的新手,目前正在处理学生数据。 I am working with the following code:我正在使用以下代码:

    x = np.arange(timepoints.shape[0])/sample_rate
    f = pl.figure(figsize = (10,3.5))
    pl.plot(x, pupil)
    pl.xlabel('Time (s)')
    pl.ylabel('Pupil size')
    sn.despine(offset=10)

Using the above code, I receive the following output:使用上面的代码,我收到以下 output:

在此处输入图像描述 I would like the y-axis limits to be within the range of 0-1000.我希望 y 轴限制在 0-1000 的范围内。 I have tried ylim and this does not seem to work and I still receive the same output.我已经尝试过ylim ,但这似乎不起作用,我仍然收到相同的 output。

Here is the new figure with the following code:这是带有以下代码的新图:

     x = np.arange(timepoints.shape[0]) / sample_rate
     f = pl.figure(figsize = (15,3.5))
     pl.plot(x, pupil)
     pl.yticks(np.linspace(0, 1000, 10))
     pl.xlabel('Time (s)')
     pl.ylabel('Pupil size (a.u)')
     sn.despine(offset=10)

enter image description here在此处输入图像描述

I've tried playing around with the numbers etc. but it still doesn't seem to cooperate.我试过玩弄数字等,但它似乎仍然不合作。

If you would have googled it before, it would be better.如果你之前用谷歌搜索过,那就更好了。 There is a way to do it,有一种方法可以做到

https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.ylim.html https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.ylim.html

Check it out!一探究竟!

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

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