【问题标题】:'Line2D' object has no property 'kind''Line2D' 对象没有属性 'kind'
【发布时间】:2020-03-03 01:51:17
【问题描述】:

我刚开始学习 pandas,当我想在创建 fig, ax = plt.subplots() 对象并将绘图添加到创建的 ax 时制作 2013 年站的平均值的条形图时,我在运行时遇到此错误这部分代码'Line2D'对象没有属性'kind'


fig,ax = plt.subplots(1)
x= data.columns
y=data['2013'].mean()
ax.plot(x,y,kind='bar')
```````````````````````

[this is my DATASET]

                      L06_347   LS06_347    LS06_348
Time            
2009-01-01 00:00:00 0.137417    0.097500    0.016833
2009-01-01 03:00:00 0.131250    0.088833    0.016417
2009-01-01 06:00:00 0.113500    0.091250    0.016750
2009-01-01 09:00:00 0.135750    0.091500    0.016250
... ... ... ...
2013-01-01 15:00:00 1.420000    1.420000    0.096333
2013-01-01 18:00:00 1.178583    1.178583    0.083083
2013-01-01 21:00:00 0.898250    0.898250    0.077167
2013-01-02 00:00:00 0.860000    0.860000    0.075000
11697 rows × 3 columns

另一方面,我尝试使用此代码选择所有不同年份的 4 月、5 月和 6 月的所有数据

data[(data.index.month == 4) & (data.index.month == 5) & (data.index.month == 6)]

我也试过这种方式

data.loc[(data.index.month == 4) & (data.index.month == 5) & (data.index.month == 6)]

它什么也没显示,只是显示空列。

【问题讨论】:

    标签: pandas datetime subplot


    【解决方案1】:

    对于您的第一个问题,您必须使用data.plot(x, y, kind='bar'),而不是ax.plot()。

    fig,ax = plt.subplots(1)
    ax = data['2013'].mean().plot(kind='bar')
    ax.set_xlabel('x label name')   # replace with the labels you want
    ax.set_ylabel('Mean')
    plt.xticks(rotation=30)
    plt.show()
    

    第二个问题 - 使用data[data.index.month.isin([4,5,6])]

    【讨论】:

    • 如果有帮助请告诉我
    猜你喜欢
    • 2021-01-06
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    相关资源
    最近更新 更多