[英]Why does plotly express give me an attribute error when I make a line chart?
I am trying to use plotly to build a line chart.我正在尝试使用 plotly 来构建折线图。 Here is the code I wrote:这是我写的代码:
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()
Why do I get the following error:为什么我会收到以下错误:
AttributeError: 'object' object has no attribute 'layout' AttributeError: 'object' object 没有属性 'layout'
Using the latest version of Plotly (version 5.4.0 at the time of posting), I can produce a line chart from your code.使用最新版本的 Plotly(发布时为 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.