【问题标题】:Plotting 2 colored labels in time series plot在时间序列图中绘制 2 个彩色标签
【发布时间】:2021-12-17 01:59:58
【问题描述】:

我有一个包含旅行电池状态(0 或 1)的数据集。我想绘制一个时间序列图,其中 x 轴具有离散时间,y 轴具有当时的车速。在旅途中,有时电池状态为 1(正在充电),有时为 0(未充电)。我一直在尝试绘制一个时间序列图,当电池状态为 0 时显示绿色,电池状态为 1 时显示红色。这是我的代码和结果:

import seaborn as sns
fig = plt.figure(figsize=(35,5)) 
ax1=plt.subplot(121)

sns.lineplot(x='index', y='VehicleSpeed_km_h_', data=trip_1567) # plot normal time series plot
sns.lineplot(x='index', y= 'VehicleSpeed_km_h_', data=trip_1567[trip_1567['Battery_Status'] == 1], color='red')

【问题讨论】:

    标签: python matplotlib time-series seaborn visualization


    【解决方案1】:

    我用散点图代替。

    import seaborn as sns
    fig = plt.figure(figsize=(35,5)) 
    ax1=plt.subplot(121)
    
    sns.scatterplot(x='index', y='VehicleSpeed_km_h_', data=trip_1567, color='green') # plot normal time series plot
    sns.scatterplot(x='index', y= 'VehicleSpeed_km_h_', data=trip_1567[trip_1567['Battery_Status'] == 1], color='red')
    

    【讨论】:

      猜你喜欢
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      相关资源
      最近更新 更多