简体   繁体   English

无法在Python Matplotlib中的y轴上显示完整的图形

[英]Cannot show complete graph on y-axis in Python Matplotlib

I am new to python and I am trying to plot in a graph in python, but the plot on y-axis is not completely visible. 我是python的新手,正在尝试在python中绘制图形,但是在y轴上的绘制并不完全可见。 I need to increase the y-limits from -1000 to 7. But, matplotlib cuts the graph above 0 in case I specify such high ylimits. 我需要将y-limits从-1000增加到7。但是,如果我指定了如此高的ylimits,则matplotlib会将图形切到0以上。 And if I specify smaller limits like -10 to 10, it doesn't show the complete graph on negative y-axis. 而且,如果我指定了较小的限制(如-10到10),则它不会在y负轴上显示完整的图形。 I tried to save figure using tight layout but that also did not help. 我试图使用紧凑的布局保存图形,但这也无济于事。

I am using Python 3.6.3 and Jupyter notebook. 我正在使用Python 3.6.3和Jupyter笔记本。

Below are the graphs for plt.ylim(-10, 5.5) and plt.ylim(-1000, 5.5), respectively. 以下分别是plt.ylim(-10,5.5)和plt.ylim(-1000,5.5)的图形。

图片1

图片2

Is there anyway to increase the y-limits to very high so that the whole graph is visible? 是否有将y限制增加到很高以使整个图形可见的方法?

Here is my code snippet for the graph: 这是我的图形代码片段:

plt.plot(tVec,psp,'b',linewidth=2,label='PSP')
plt.ylim(-10, 5.5)
plt.xlabel("Time (ms)")
plt.ylabel("PSP")
plt.legend()
plt.savefig("test.png",bbox_inches='tight')
plt.show()

If you want to see the y axis as a logarithmic one ( Wikipedia Logarithmic Scale ) you could set it up with plt.yscale('log') 如果您想将y轴视为对数轴( Wikipedia对数刻度 ),则可以使用plt.yscale('log')

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

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