英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论