【问题标题】:Pandas multiple dataset plot errorPandas 多数据集绘图错误
【发布时间】:2018-08-10 18:21:50
【问题描述】:

我有多个数据集需要绘制在相同的轴上。 数据集的一个示例是: 数据集 01 作为两个单独的列表:

Waves          Values
340            520
341            532
342            536
.              .
.              .
2500           720

Dataset 02 作为数据框 df:

Wavelength      Data
320             560
350             572
.               .
.               .
2650            780

我对剧情的尝试如下:

fig,ax=plt.subplots(figsize=(15, 10))
ax = plt.plot(x = Waves , y = Values)   # list names
df.plot(ax=ax, x='Wavelength', y='Data')
plt.show()

我收到以下错误:

AttributeError: 'list' object has no attribute 'get_figure'

【问题讨论】:

    标签: python python-3.x pandas dataframe matplotlib


    【解决方案1】:

    您通过ax=plt.plot(..) 将在第一行中创建的轴ax 重新定义为行列表。删除这个重新定义。

    fig,ax=plt.subplots(figsize=(15, 10))
    ax.plot(Waves, Values)
    df.plot(ax=ax, x='Wavelength', y='Data')
    plt.show()
    

    【讨论】:

    • 这确实消除了错误,但它根本没有绘制 (x= Waves, y = Values)....只是 df.plot (只有蓝线图在我的示例输出图片)
    • 抱歉,我只是从您的代码中复制了它而没有经过测试,因为没有 minimal reproducible example。问题是 matplotlib 图的 xy 参数没有命名参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 2021-01-19
    • 1970-01-01
    • 2018-12-14
    • 2022-01-07
    • 2015-01-02
    • 1970-01-01
    相关资源
    最近更新 更多