用大间隔值绘制函数

huangapple go评论52阅读模式
英文:

plot function with large interval values

问题

我试图绘制|sin(x)|/x在范围x=[1e27,1e33]内。

x=np.logspace(27,33,1000000)
plt.plot(abs(np.sin(x))/x)
plt.xscale('log')

答案应该是一个平滑的阻尼振荡器,但我得到的是这个结果:
用大间隔值绘制函数

我猜这是因为我使用的数字太大了,有什么建议吗?

英文:

I'm trying to plot |sin(x)|/x in range x=[1e27,1e33].

x=np.logspace(27,33,1000000)
plt.plot(abs(np.sin(x))/x)
plt.xscale('log')

The answer has to be a smooth damping oscillator but this is what I get:
用大间隔值绘制函数

I guess this is because of the large numbers I'm working with, any suggestions ?

答案1

得分: 1

plt.plot(abs(np.sin(x))/x) 中,您仅指定了y坐标,因此matplotlib对x坐标使用了整数。由于您有1000000个x点,matplotlib x轴范围从0到1e06。

尝试这样做:

plt.plot(x, abs(np.sin(x))/x)
英文:

In plt.plot(abs(np.sin(x))/x) you only specified the y-coordinates, hence matplotlib used integers for the x-coordinates. Since you have 1000000 x-points, matplotlib x-axis goes from 0 to 1e06.

Try this:

plt.plot(x, abs(np.sin(x))/x)

huangapple
  • 本文由 发表于 2023年5月13日 21:42:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76243030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定