首页 > 解决方案 > 如何使动画在 plotly_express 绘图的 powerpoint 文件中工作?

问题描述

我正在使用 plotly express 生成一些带有动画的情节。例如,animation_frame='Year'用于更改不同年份的散点图。而且我喜欢将绘图复制到 Powerpoint 文件中。我想知道当我进行演示时是否有可能将动画保留在 Powerpoint 文件中?谢谢

以下是示例代码:

import pandas as pd
import plotly.express as px
import plotly as py

url_co2 = 'https://raw.githubusercontent.com/TrainingByPackt/Interactive-Data-Visualization-with-Python/master/datasets/co2.csv'
url_gm = 'https://raw.githubusercontent.com/TrainingByPackt/Interactive-Data-Visualization-with-Python/master/datasets/gapminder.csv'
co2 = pd.read_csv(url_co2)
gm = pd.read_csv(url_gm)
df_gm = gm[['Country', 'region']].drop_duplicates()
df_w_regions = pd.merge(co2, df_gm, left_on='country', right_on='Country', how='inner')
df_w_regions = df_w_regions.drop('Country', axis='columns')
new_co2 = pd.melt(df_w_regions, id_vars=['country', 'region'])
columns = ['country', 'region', 'year', 'co2']
new_co2.columns = columns
df_co2 = new_co2[new_co2['year'].astype('int64') > 1963]
df_co2 = df_co2.sort_values(by=['country', 'year'])
df_co2['year'] = df_co2['year'].astype('int64')
df_gdp = gm[['Country', 'Year', 'gdp']]
df_gdp.columns = ['country', 'year', 'gdp']
data = pd.merge(df_co2, df_gdp, on=['country', 'year'], how='left')
data = data.dropna()
data.head()

scat1 = px.scatter(data, x = 'gdp', y = 'co2', color = 'region', marginal_y = 'box', marginal_x = 'rug', animation_frame = 'year', animation_group = 'country')
py.offline.plot(scat,filename='output.html')

标签: expressanimationplotlypowerpoint

解决方案


推荐阅读