express - 如何使动画在 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')
解决方案
推荐阅读
- javascript - 如何将 mjs 文件中的特定数据发送到 API 服务器?
- angular - 为什么 Visual Studio 2019 会自动设置 git 源代码管理?
- javascript - 有没有办法在 SharePoint 页面上获取当前页面的标题
- c# - 如何在 C# 应用程序中隐藏谷歌工作表令牌?
- button - 更改 mailchimp 中按钮的形状
- perl - 如何在 perl 中使用 \e 元字符拆分字符串?
- cucumber - 黄瓜异常:无法加载插件类:com.epam.reportportal.cucumber.ScenarioReporter
- php - 从 MYSQL 查询临时存储变量
- image - scipy.misc 图像函数(例如 imread、imresize、imsave、imshow 等)上的 AttributeError、ImportError
- c++ - 在 macOS 上的另一个窗口中打开小部件