我试图用matplotlib绘制一个特定的过程(随时间的加速)。到目前为止,该图仍在运行,正在显示中(见图)。J等于35,表示加速度随时间的导数(在本例中为常数)
import numpy as np
import matplotlib.pyplot as plt
def limits_acc_course():
limits_acc_course.t1 = 0.14285714285714285
limits_acc_course.t2 = 0.14285714285714285 + 0.10714285714285715
limits_acc_course.t3 = 2*0.14285714285714285 + 0.10714285714285715
limits_acc_course.t4 = 2*0.14285714285714285 + 0.10714285714285715 + 0.5*0.24714285714285716
limits_acc_course()
t_end = 2*limits_acc_course.t4
t_1 = np.linspace(0, limits_acc_course.t1)
t_2 = np.linspace(limits_acc_course.t1, limits_acc_course.t2)
t_3 = np.linspace(limits_acc_course.t2, limits_acc_course.t3)
t_4 = np.linspace(limits_acc_course.t3, limits_acc_course.t4)
tk1 = np.array([])
tk2 = np.array([])
tk3 = np.array([])
tk4 = np.array([])
for value1 in t_1:
tk1 = np.append(tk1, value1*j)
for value2 in t_2:
tk2 = np.append(tk2, limits_acc_course.t1*j)
for value3 in t_3:
tk3 = np.append(tk3, (limits_acc_course.t3-value3)*j)
for value4 in t_4:
tk4 = np.append(tk4, value4*0)
if value4 == (2*limits_acc_course.t4-limits_acc_course.t3)*j:
break
t = np.concatenate((tk1, tk2, tk3, tk4), axis=0)
t_neg = (-1)*np.concatenate((tk1, tk2, tk3), axis=0)
t_final = np.concatenate((t, t_neg), axis=0)
t_range = np.linspace(0, t_end, t_final.size)
fig, t = plt.subplots()
t.plot(t_range, t_final)
t.get_xaxis().get_major_formatter().set_useOffset(False)
plt.show()
问题是绘图中的x坐标与计算值不匹配
绘图(见图)中的x值应为: 0.142857142857 0.25 (或至少有这样一个accuracy:0.1429)你知道吗
图中的x值为。 0.144777 0.295348
我试过关闭偏移量,每个部分的值在100到2500之间,我试过四舍五入,但也没用。此外,我还尝试使用endpoint=False来创建范围t_1到t_4
现在我已经没有主意了
绘图是在屏幕上延伸超过500像素的轴上创建的。x轴显示1.1个单位。因此,每像素有1.1/500=0.0022个单位。鼠标光标不能比1像素更准确地知道其位置。因此,鼠标光标显示的坐标精确到~±0.0022单位
观测坐标(0.144777)与实际坐标(0.142857142857)相差0.0019个单位,在光标的精度范围内
相关问题 更多 >
编程相关推荐