首页 > 解决方案 > 使用 matplotlib 时,为什么我的绘图数据会压缩?

问题描述

我正在将 .csv 文件转换为熊猫数据框。当我使用 python 绘制数据框时,我的数据被压缩了。附上matplotlib生成的图,excel生成的图。excel中数据的范围是0到140小时。

1

但是在python生成的数字上,只有0到75小时。

2

这是代码片段: # 如何使用 open(file,'r') as csv_file 打开 csv 文件:df=pd.read_csv(csv_file, header=None,names=columns,usecols=['Timestamp', '传感器 5 (DO)','O2']) df.drop(index=df.index[0],axis=0,inplace=True)

#This plots two columns on the same plot
fig,ax1 = plt.subplots()
ax2 = ax1.twinx()

plt_1 = ax1.plot(df['Timestamp'],df['Sensor 5 (DO)'],'ro',label='Sensor 5 (DO)',)
plt_2 = ax2.plot(df['Timestamp'],df['O2'],'ko',label='O2')

leg = plt_1 + plt_2
labs = [l.get_label() for l in leg]

ax1.legend(leg, labs)

ax1.set_xlabel("Time")
ax1.set_ylabel("DO Saturation (%)")
ax2.set_ylabel("Sparged Oxygen Flow Rate (sccm)")

数据头示例集:

,时间戳,传感器 5 (DO),O2 1,4/13/2021 10:32,, 2,4/13/2021 10:33,67.89,0 3,4/13/2021 10:33,69.21,0 4,4/13/2021 10:34,71.66,0 5,4/13/2021 10:34,72.92,0 6,4/13/2021 10:35,74.41,0 7,4/13/2021 10 :35,76.04,0 8,4/13/2021 10:36,77.61,0 9,4/13/2021 10:36,79.3,0 10,4/13/2021 10:37,81.02,0 11, 4/13/2021 10:37,82.85,0 12,4/13/2021 10:38,84.52,0 13,4/13/2021 10:38,86.3,0 14,4/13/2021 10:39 ,88.1,0 15,4/13/2021 10:39,89.61,0

尾部:,时间戳,传感器 5 (DO),O2 17353,4/19/2021 11:11,100,0 17354,4/19/2021 11:11,100,0 17355,4/19/2021 11:12,100,0 17356, 4/19/2021 11:12,100,0 17357,4/19/2021 11:13,100,0 17358,4/19/2021 11:13,100,0 17359,4/19/2021 11:14,100,0 17360,4/ 19/2021 11:14,100,0 17361,4/19/2021 11:15,100,0 17362,4/19/2021 11:15,100,0 17363,4/19/2021 11:16,100,0 17364,4/19/ 2021 11:16,100,0 17365,4/19/2021 11:17,100,0 17366,4/19/2021 11:17,100,0 17367,4/19/2021 11:18,100,0

标签: pythonpandascsvmatplotlib

解决方案


推荐阅读