【问题标题】:Why does plotly express give me an attribute error when I make a line chart?为什么在我制作折线图时,plotly express 会给我一个属性错误?
【发布时间】:2022-01-03 01:27:51
【问题描述】:

我正在尝试使用 plotly 来构建折线图。这是我写的代码:

from fredapi import Fred
import plotly.express as px
fred = Fred("1c242ee90989c94ffb93c923d94e855f")
tran = pd.DataFrame(fred.get_series("EMISSCO2TOTVTCTOUSA"))
tran.columns = ["CO2"]
tran = tran.reset_index()
fig = px.line(tran, x = "index", y = "CO2")
fig.show()

为什么会出现以下错误:

AttributeError: 'object' 对象没有属性 'layout'

【问题讨论】:

  • 请发布完整错误信息
  • 我可以根据您的代码生成折线图。您使用的是什么版本的 Plotly?

标签: python plotly


【解决方案1】:

使用 Plotly 的 latest version(发布时版本为 5.4.0),我可以从您的代码中生成折线图。

from fredapi import Fred
import plotly.express as px
fred = Fred("1c242ee90989c94ffb93c923d94e855f")
tran = pd.DataFrame(fred.get_series("EMISSCO2TOTVTCTOUSA"))
tran.columns = ["CO2"]
tran = tran.reset_index()
fig = px.line(tran, x = "index", y = "CO2")
fig.show()

【讨论】:

    猜你喜欢
    • 2021-09-03
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    相关资源
    最近更新 更多