[英]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.