gpt4 book ai didi

python - 如何在 Matplotlib 中为多个图形设置静态 Y 轴?

转载 作者:太空宇宙 更新时间:2023-11-04 08:27:40 24 4
gpt4 key购买 nike

<分区>

我的 Python 代码有问题。我将一个物理项目的一些测试结果写入了一个 csv 文件。然后,我编写了一个 Python 脚本,该脚本使用 matplotlib 在图表中展示结果。基本上,我有 10 个不同的系列(例如位置、速度、加速度和秒),我希望它们在一个图中。

但问题是:它完全改变了我的 Y 轴值,我不知道为什么。我只想要一个从 -11 的静态 Y 轴,然后填充不同的值。 X轴很好;这些是我的秒数。

enter image description here

我用 plt.axisplt.axes 尝试了一些东西,但我真的被困在这里了。这是我正在谈论的代码片段:

import csv
import sys
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as tick


positionM1 = []
positionM2 = []
velocityM1 = []
velocityM2 = []
accel1 = []
accel2 = []
sec = []
forceM1 = []
forceM2 = []
federPressed = []


with open("filename", 'r') as csvfile:
plots= csv.reader(csvfile, delimiter=',')
for row in plots:
sec.append((row[0]))
velocityM1.append((row[1]))
velocityM2.append((row[2]))
positionM1.append((row[3]))
positionM2.append((row[4]))
accel1.append((row[5]))
accel2.append((row[6]))
forceM1.append((row[7]))
forceM2.append((row[8]))
federPressed.append((row[9]))



plt.axis('normal')
plt.plot(sec, velocityM1, 'b', sec, velocityM2, 'g', sec, positionM1, 'r')
plt.plot(sec, velocityM2, label="VelocityM2")
plt.plot(sec, positionM1, label="PositionM1")
plt.plot(sec, positionM2, label="PositionM2")
plt.plot(sec, accel1, label="AccelerationM1")
plt.plot(sec, accel2, label="AccelerationM2")
plt.plot(sec, forceM1, label="Newton M1")
plt.plot(sec, forceM2, label="Newton M1")
plt.plot(sec, federPressed, label="Feder gepresst")
plt.legend(fontsize=10)
plt.grid('True')


plt.show()

这是 CSV 文件:

0.0000,0.5000,0.0000,0.0000,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.0250,0.5000,0.0000,0.0125,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.0500,0.5000,0.0000,0.0250,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.0750,0.5000,0.0000,0.0375,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1000,0.5000,0.0000,0.0500,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1250,0.5000,0.0000,0.0625,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1500,0.5000,0.0000,0.0750,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.1750,0.5000,0.0000,0.0875,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2000,0.5000,0.0000,0.1000,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2250,0.5000,0.0000,0.1125,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2500,0.5000,0.0000,0.1250,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.2750,0.5000,0.0000,0.1375,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3000,0.5000,0.0000,0.1500,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3250,0.5000,0.0000,0.1625,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3500,0.5000,0.0000,0.1750,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.3750,0.5000,0.0000,0.1875,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.4000,0.5000,0.0000,0.2000,0.3000,0.0000,0.0000,0.0000,0.0000,0.0000,
0.4250,0.4500,0.0500,0.2113,0.3012,-2.0000,2.0000,-1.0000,1.0000,0.1000,
0.4500,0.4050,0.0950,0.2214,0.3036,-1.8000,1.8000,-0.9000,0.9000,0.0900,
0.4750,0.3639,0.1361,0.2305,0.3070,-1.6450,1.6450,-0.8225,0.8225,0.0822,
0.5000,0.3256,0.1744,0.2386,0.3114,-1.5311,1.5311,-0.7656,0.7656,0.0766,
0.5250,0.2892,0.2108,0.2458,0.3167,-1.4555,1.4555,-0.7278,0.7278,0.0728,
0.5500,0.2538,0.2462,0.2522,0.3228,-1.4163,1.4163,-0.7082,0.7082,0.0708,
0.5750,0.2185,0.2815,0.2576,0.3299,-1.4125,1.4125,-0.7063,0.7063,0.0706,
0.6000,0.1824,0.3176,0.2622,0.3378,-1.4440,1.4440,-0.7220,0.7220,0.0722,
0.6250,0.1446,0.3554,0.2658,0.3467,-1.5116,1.5116,-0.7558,0.7558,0.0756,
0.6500,0.1042,0.3958,0.2684,0.3566,-1.6170,1.6170,-0.8085,0.8085,0.0809,
0.6750,0.0601,0.4399,0.2699,0.3676,-1.7629,1.7629,-0.8814,0.8814,0.0881,
0.7000,0.0113,0.4887,0.2702,0.3798,-1.9528,1.9528,-0.9764,0.9764,0.0976,

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com