[英]Plotting exponential function
I'm relatively new to Python.我对 Python 比较陌生。 I'm trying to plot exponential term value ranging between 0 and 100. There is no error indicated with the code but the Plot has no legend(line).我正在尝试 plot 指数项值介于 0 和 100 之间。代码没有指示错误,但 Plot 没有图例(行)。 Kindly help me.请帮助我。 Thank you.谢谢你。
import math
import matplotlib.pyplot as plt
for i in range (0,101):
m = math.exp(i)
print("For i = ",i)
print("(e^i) = ",m)
plt.plot(i,m,'b--',linewidth=3)
plt.ylabel('e^i')
plt.xlabel('i')
plt.show()
You can change your code in this way:您可以通过以下方式更改代码:
import math
import matplotlib.pyplot as plt
l = list(range (0,101))
m_l = []
for i in l:
m = math.exp(i)
print("For i = ",i)
print("(e^i) = ",m)
m_l.append(m)
plt.plot(l,m_l,'b--',linewidth=3)
plt.ylabel('e^i')
plt.xlabel('i')
plt.legend(['m_l'])
plt.show()
With your code, you were plotting just the last values of i
and m
使用您的代码,您只绘制了i
和m
的最后一个值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.