简体   繁体   English

为什么plotly express做折线图时会提示属性错误?

[英]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.

相关问题 为什么%config行在Python 3.7中给我语法错误? - Why does %config line give me syntax error in Python 3.7? 为什么我会出现情节表达属性错误? (AttributeError: 'Figure' 对象没有属性 'add_hline' - Why am I getting plotly express attribute error? (AttributeError: 'Figure' object has no attribute 'add_hline' 为什么python在我导入模块时给我一个错误? - Why does python give me an error when i am importing modules? 为什么当我尝试导入 function、class 等时 VS studio 给我一个错误 - Why does VS studio give me an error when I try to import a function, class, etc 为什么在更改输入数量时插值会给我一个错误 - Why does interpolation give me an error when I change the number of inputs 当我尝试运行 Beautiful Soup 时,为什么 Jupyter 会给我一个 ModSecurity 错误? - Why does Jupyter give me a ModSecurity error when I try to run Beautiful Soup? 为什么 g 在这种 if 条件下使用时会给我错误? - Why does g give me error when used in this if condition? 为什么我在导入 discord.py 时总是给我一个错误? - Why does it always give me an error, when I import discord.py? 为什么我运行该代码时会给我一个NameError? - Why does this code give me a NameError when I run it? 为什么这个dict会给我一个语法错误? - Why does this dict give me a syntax error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM