【发布时间】:2015-11-26 13:36:50
【问题描述】:
我有两个功能。两者都使用相同的 x 轴,但与另一个函数相比,一个函数的 y 轴值太高,因此一个函数会保持平缓。如何为第二个函数创建辅助 y 轴,以便我可以在一个绘图上查看这两个函数?
这是我的代码:
import math
import matplotlib.pyplot as plt
g = 9.81
vo = 14.5
zo = 2.35
m = 7.257
sin = (vo/((2*((vo**2)+g*zo))**(1/2)))
alpha = math.asin(sin)
tan = math.tan(alpha)
z= []; x = []; E = []
for i in range(1000):
x.append(i*(1/41))
z.append(-(g/2)*((x[i]**2)/(vo**2))*(1+tan**2)+tan*x[i]+zo)
E.append(m*g*z[i])
if len(z)>=3:
if z[-1]<=0 and z[-2]>0:
x0 = (x[-1] + x[-2])/2
if z[-2]>z[-1] and z[-2]>z[-3]:
zmax=z[-2]
xmax=x[-2]
fig = plt.figure()
plt.title("Wurf der Kugel")
plt.ylim(-1,700)
plt.xlim(0,25)
plt.xlabel("Distanz in m")
plt.ylabel("Hoehe in m")
dotx0=(x0,0)
dotmax=(xmax,zmax)
print("Die Wurfweite ist bei {}. Das Maximum ist bei {}".format(dotx0,dotmax))
plt.plot(x0,0,"o", markersize = 8, label=dotx0)
plt.plot(xmax,zmax,"o", markersize = 8, label=dotmax)
plt.grid(True)
plt.legend()
plt.plot(x,z)
plt.plot(x,E)
plt.show()
非常感谢!
【问题讨论】:
标签: python matplotlib