python - 使用 matplotlib 时,为什么我的绘图数据会压缩?
问题描述
我正在将 .csv 文件转换为熊猫数据框。当我使用 python 绘制数据框时,我的数据被压缩了。附上matplotlib生成的图,excel生成的图。excel中数据的范围是0到140小时。
但是在python生成的数字上,只有0到75小时。
这是代码片段: # 如何使用 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
解决方案
推荐阅读
- gradle - gradle from("originPath") 和 into("targetPath") 如何以及为什么删除文件?
- c - 矩阵乘法的不准确性 - C
- python - 如何从有条件的主列表中制作几个列表
- json - 我在将 HTML 脚本解码为 JSON 中的字符串值时遇到问题,其他所有值都被转换得很好
- python - 从存储为实例变量的 Entry 小部件中检索输入并在类外部使用它
- delphi-10-seattle - 如何在delphi中将特定的子窗体分配给Activeform
- yarnpkg - 使用 Yarn 工作区时,我可以在根工作区中安装每个 devDependency 吗?或者我应该将它们保存在每个单独的工作区中?
- swift - 依赖注入 pointfree.co-style:有依赖的依赖?
- github - 如何在自定义 vscode github 问题查询中按里程碑组织问题?
- docker - 如何隐藏终止为连续服务的 docker 映像