Plotly 动画:折线图不可见(Python)
我正在 Jupyter Notebook 中工作,试图显示动画折线图。 (看到它是从左到右绘制的。)
但是,当图表容器和所有控件都显示时,图表不会显示。就好像这条线是看不见的。
这是我的代码:
import pandas as pd
import plotly.express as px
import plotly.io as pio
data = [['Year', 'Country', 'Output', 'Investment', 'Depreciation'], ['2020', 'Netherlands', 1, 2, 1], ['2021', 'Netherlands', 2, 2, 1], ['2022', 'Netherlands', 3, 2, 1], ['2023', 'Netherlands', 4, 2, 1]]
df = pd.DataFrame(data[1:], columns=data[0])
pio.renderers.default = 'notebook'
px.line(df,
x='Year',
y='Output',
color='Country',
title='Macroeconomic variables over time',
range_x=[df['Year'].iloc[0], df['Year'].iloc[-1]],
range_y=[0, max(df['Output']) * 1.25],
animation_frame='Year')
给出以下图表(在 VSCode 和 Jupyter Notebook 中):
关于为什么会发生这种情况有什么想法吗?
I am working in a Jupyter Notebook trying to display a line chart being animated. (Seeing it being plotted from left to right.)
However, the chart doesn't show up while the chart container and all controls do show up. It is like the line is invisible.
This is my code:
import pandas as pd
import plotly.express as px
import plotly.io as pio
data = [['Year', 'Country', 'Output', 'Investment', 'Depreciation'], ['2020', 'Netherlands', 1, 2, 1], ['2021', 'Netherlands', 2, 2, 1], ['2022', 'Netherlands', 3, 2, 1], ['2023', 'Netherlands', 4, 2, 1]]
df = pd.DataFrame(data[1:], columns=data[0])
pio.renderers.default = 'notebook'
px.line(df,
x='Year',
y='Output',
color='Country',
title='Macroeconomic variables over time',
range_x=[df['Year'].iloc[0], df['Year'].iloc[-1]],
range_y=[0, max(df['Output']) * 1.25],
animation_frame='Year')
Giving the following chart (in both VSCode and Jupyter Notebooks):
Any ideas on why this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)