我希望我的y轴与此图像中的y轴重叠/移动:
下面是我使用python创建的图形,代码如下所示:
在我绘制的图上只有一个原点。我希望至少有三个,以便振幅较小的函数更清晰/更易于阅读
我可以使用哪些功能来实现这一点
谢谢大家!
import numpy as np
import matplotlib.pyplot as plt
import math
def initial():
#obtain inital parameters
dt = .04
g = 9.8
l = 9.8
q = 0.5
f_d = 1.2 #driving force
frequency = 0.667 #frequency of driving force
theta_start = 0.2
omega_start = 0
time_stop = 60
return dt, g, l, q, frequency, theta_start, omega_start, time_stop
def rk_2(dt, g, l, q, frequency, theta_start, omega_start, time_stop):
#create arrays for theta and omega, calculate omega and theta using rk2 method
forces = [0, 0.5, 1.2]
j = 0
while j < 3:
f_d = forces[j]
theta = []
omega = []
time = [np.array([0])]
theta = np.append(theta, theta_start)
omega = np.append(omega, omega_start)
i = 0
while time[i] < time_stop:
#if theta[i] not in range(-3.14,3.14)
theta_prime = theta[i] + 0.5*omega[i]*dt
omega_prime = omega[i] + 0.5*((-g/l)*math.sin(theta[i]) - q*omega[i] + f_d*math.sin(frequency*time[i]))*dt
time_prime = time[i] + 0.5*dt
theta_new = theta[i] + omega_prime*dt
omega_new = omega[i] + ((-g/l)*math.sin(theta_prime) - q*omega[i] + f_d*math.sin(frequency*time_prime))*dt
time_new = time[i] + dt
theta = np.append(theta, theta_new)
omega = np.append(omega, omega_new)
time = np.append(time, time_new)
i = i + 1
plt.plot(time, theta)
j = j+1
plt.plot(time, theta)
plt.xlabel('Time [s]')
plt.ylabel('Angle [rad]')
plt.show()
return theta, omega, time
def main():
dt, g, l, q, frequency, theta_start, omega_start, time_stop = initial()
theta, omega, time = rk_2(dt, g, l, q, frequency, theta_start, omega_start, time_stop)
#plot(theta, omega, time)
main()
可以修改@tom10的comment中引用的答案,以确保所有子地块的勾号间距一致,即使子地块的高度不同,也可以通过显式设置每个子地块的勾号位置(和标签)以及限制:
相关问题 更多 >
编程相关推荐