【问题标题】:Plotting line(color, attribue defined) graph using pandas使用熊猫绘制线(颜色,属性定义)图
【发布时间】:2015-09-24 18:34:16
【问题描述】:

我尝试使用 pandas grouby 数据集绘制具有不同属性(颜色、线型等)的多线。我的代码绘制了多个源的所有蓝线。 如何在每组应用线属性?

我的代码失效了。

from pandas import Series, DataFrame
import pandas as pd
import matplotlib.pyplot as plt

xls_file = pd.ExcelFile(r'E:\SAT_DATA.xlsx')
glider_data = xls_file.parse('Yosup (4)', parse_dates=[0])
each_glider = glider_data.groupby('Vehicle') 

fig, ax = plt.subplots(1,1); 
glider_data.groupby("Vehicle").plot(x="TimeStamp", y="Temperature(degC)", ax=ax)
plt.legend(glider_data['Vehicle'], loc='best')
plt.xlabel("Time")
plt.ylabel("Temp")
plt.show()

【问题讨论】:

标签: python pandas matplotlib


【解决方案1】:

我认为您需要遍历来自groupby 的组。比如:

for i,group in glider_data.groupby('Vehicle'):
    group.plot(x='TimeStamp', y='Temperature(degC)', ax=ax, label=i)

【讨论】:

  • 谢谢汤姆,但是您的建议在没有标签选项的情况下会带来相同的结果。 label 选项产生解析错误。
猜你喜欢
  • 2021-02-09
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 2018-10-15
相关资源
最近更新 更多