秃头宝贝。 2022-02-18 18:04 采纳率: 58.3%
浏览 42
已结题

用python画时间速度图,怎么将处理后的时间速度图画出来


# noinspection PyUnresolvedReferences
import pandas as pd
# noinspection PyUnresolvedReferences
import numpy as np
# noinspection PyUnresolvedReferences
import seaborn as sns
# noinspection PyUnresolvedReferences
import matplotlib.pyplot as plt

df=pd.read_csv('E:/车辆轨迹数据-6月/071201-200/M8005170-20210601-20210630.csv')

col=df.columns.values
df.columns=[x.strip() for x in col]     ###首行文字去前后空格
df.drop_duplicates(subset=['gpstime'],keep='first',inplace=True)  ##删除gps时间重复的列
####数据预处理—————排序
df_paixu=df.sort_values(by=['gpstime'],ascending=[1])
df_paixu=df_paixu.reset_index(drop=True)  ###重置排序后数列的index
df_paixu['gpstime']=(df_paixu['gpstime']-min(df_paixu['gpstime']))/1000
t=df_paixu['gpstime']
#####数据预处理————数据单位转化为标准单位及百分比
df_paixu['speed']=(df_paixu['speed'])/100/3.6   #车速单位km/h

##速度修正
def v(vt):
    l=df_paixu['speed']
    for i in vt:
        if i<=3.6:
            l.append(0)
        elif i<=7.2:
            l.append(7.2-(7.2/(7.2-3.6))*(7.2-i))
        else:
            l.append(i)
    return l
'''if df_paixu['speed']<=3.6:
    eq1 = 0
elif 3.6<df_paixu['speed']<=7.2:
    eq2 = 7.2 - (7.2 / (7.2 - 3.6)) * (7.2 - df_paixu['speed'])
else:
    eq3 = df_paixu['speed']
df_paixu['speed'][eq1&eq2&eq3]'''

'''##读取1-500s时间段内的数据
open_time='0.00'
close_time='500.00'
con1=df_paixu['gpstime']>=open_time
con2=df_paixu['gpstime']<close_time
df[con1&con2]'''
##

##画图
x = df.loc[:,'gpstime']# 读取csv文件中的某两列
y = df.loc[:,'speed']
plt.plot(x,y,color='r', label=u'1路')  # 绘制x,y的折线图
plt.savefig(r'C:\Users\歪歪\Desktop\工况预估\1.jpg')#保存图片
plt.show()  # 显示折线图

###出现问题
最后的图还是未处理的数据图

img

怎么将处理之后的数据重新画图

  • 写回答

1条回答 默认 最新

  • youcans_ 人工智能领域优质创作者 2022-02-18 20:39
    关注

    用 df.loc[:,'gpstime'],df.loc[:,'speed']作为横坐标、纵坐标绘图,程序中除了对 df 去重,df 并没有改变(df_paixu 有变化),图中当然还是未处理的数据图。
    要绘制处理后的数据图,应该是用 df_paixu 作为横坐标、纵坐标绘图吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月19日
  • 已采纳回答 2月19日
  • 创建了问题 2月18日

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line