【发布时间】:2017-08-30 06:22:43
【问题描述】:
plt.show(),显示一个窗口,但上面没有曲线。
我的代码:
In [1]: import math
In [2]: import numpy as np
In [3]: import matplotlib.pyplot as plt
In [4]: Lm=0
In [5]: for angle in np.arange(0.0,90.0,0.1):
...: theta = angle*math.pi/180
...: L=0.25*(math.cos(theta))*(5*math.sin(theta)+math.sqrt(25*math.sin(theta)*math.sin(theta)+80))
...: print(L,"\t",angle)
...: if L>Lm:
...: Lm=L
...:
In [6]: plt.figure(1)
Out[6]: <matplotlib.figure.Figure at 0x284e5014208>
In [7]: for angle in np.arange(0.0,90.0,0.1):
...: celta = angle*math.pi/180
...: L=0.25*(math.cos(theta))*(5*math.sin(theta)+math.sqrt(25*math.sin(theta)*math.sin(theta)+80))
...: plt.figure(1)
...: plt.plot(angle,L)
...:
In [8]: plt.show()
输出
【问题讨论】:
-
每次调用
plt.plot,都会将Lines对象添加到Figure实例中。Lines对象尝试在按顺序给定的点之间创建线(线性插值)。现在的问题是,要制作一条线,至少需要两个点,但每次调用plt.plot时,您都会创建一个只有一个点的Lines对象。这就是为什么你什么都看不到。改用 NumPy 的通用函数sin和cos并让它们与数组一起工作。
标签: python matplotlib anaconda