简体   繁体   English

为什么用Semilogx函数python绘制多条线时只有一条线变为零

[英]Why only one line goes to zero when several lines are plotted with semilogx function python

I am trying to several logarithimic lines in the one plot with "semilogx fuction" by python. 我正在尝试使用python的“ semilogx功能”在一个情节中使用多条对数线。 However, only one line goes to zero and other lines don't exactly go to zero even though they should go to zero. 但是,只有一行变为零,而其他行即使变为零也不会完全变为零。 The code is: 代码是:

ustar1 = 0.15
z0=0.0002
z1 = 0.05
z2 = 0.25
z3 = 0.5
z4 = 5.0
k = 0.4

zp1 = np.arange(0.00,300,0.01)
M1 = (ustar1/k)*np.log(zp1/z0)
M2 = (ustar1/k)*(np.log(zp1/z1))
M3 = (ustar1/k)*(np.log(zp1/z2))
M4 = (ustar1/k)*np.log(zp1/z3)
M5 = (ustar1/k)*(np.log(zp1/z4))
plt.semilogx(M1,zp1,'k',label='z0=0.0002')
plt.semilogx(M2,zp1,'b',label='z0=0.05')
plt.semilogx(M3,zp1,'g',label='z0=0.25')
plt.semilogx(M4,zp1,'m',label='z0=0.5')
plt.semilogx(M5,zp1,'r',label='z0=5.0')

As shown aboce, M1 to M5 should go to zero when zp1 equal to z0 to z4 and when I printed them, it did. 如上所示,当zp1等于z0到z4时,M1到M5应该为零,而当我打印它们时,它确实应该为零。 However when I plotted it only M5 went to zero, other didb't. 但是,当我绘制它时,只有M5变为零,其他则没有。 When I removed plot for M5, the plot for M4 went to zero and others didn't and when removed M5 and M4, M3 did same thing. 当我删除M5的图时,M4的图变为零,而其他人则没有,而当删除M5和M4时,M3做同样的事情。

I am not sure why this kind of thing happens. 我不确定为什么会发生这种事情。 Is it because of the semilogx function itself? 是因为Semilogx函数本身吗? Anyhelp or advice would be really appreciated. 任何帮助或建议,将不胜感激。 Thank you, Isaac 谢谢以撒

zp1 = np.arange(0.00, 300, 0.01)
M1 = (ustar1/k)*np.log(zp1/z0)

You realize you are taking the log(0)? 您意识到自己正在使用log(0)吗? zp1[0] is 0.0, so its log is infinite. zp1 [0]为0.0,因此其对数是无限的。

If you change the range to np.arange(0.01, 300, 0.01) avoid that problem. 如果将范围更改为np.arange(0.01,300,0.01),请避免该问题。

About 'going through 0': When does this curve go through 0? 关于“通过0”:该曲线何时通过0? I think there is some confusion 我觉得有些困惑

  • You are plotting the results (M1...) on the X axis. 您正在X轴上绘制结果(M1 ...)。 Was that the idea? 是这个主意吗? The y values are the z0..z4 you defined, which are all positive. y值是您定义的z0..z4,均为正数。

  • If you swap x, y (Mx, zx) you get: 如果交换x,y(Mx,zx),则会得到:

在此处输入图片说明

暂无
暂无

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

相关问题 为什么在Python的matplotlib中将非零值绘制为零? - why a non-zero value is plotted as zero in matplotlib in python? 为什么 plt.grid 函数为我的绘制数据设置一个完整的灰色背景,而不是只设置一些网格线? Python相关 - Why is the plt.grid function setting a complete grey background for my plotted data instead of just setting some grid lines? Python related 删除 python 中绘制的 function - Delete plotted function in python 为什么我的python函数只用文件中的一行填充字典? - Why is my python function only populating a dictionary with one line from a file? 在 Python 中创建嵌套列表/元组:为什么只创建一个外部列表和几个内部列表时,外部列表也表示为相乘? - Nested lists/tuples on creation in Python: why is outer list represented as multiplied too when only creates one outer and several inner ones? Python:semilogx,包括 0 - Python: semilogx including 0 Python 将带有几行的常规 function 移动到 lambda - Python moving a regular function with several lines to a lambda 当我尝试将文本行从输入文件复制到输出文件时,Python 输出“无”,并在每一行进行编号 - Python outputs "None" when I try to copies the lines of text from the input file to the output file, numbering each line as it goes 即使图像在Python中的OpenCV中包含许多行,Hough Line Transform也只识别一行 - Hough Line Transform identifies only one line even though image contains many lines in OpenCV in Python 在一行和几行上写东西之间的区别 - Difference between writing something on one line and on several lines
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM