首页 > 解决方案 > 我正在尝试使用 plotly 创建一个热图,它会显示某种受 covid 影响的区域的动画,但它有一些问题

问题描述

所以下面是代码,我跑去获取我的热图。

问题是某些国家/地区并非每天都有更新的行,因此在其中一个国家出现行之前会有一些缺失的天数。这反映在 choropleth 地图中,它显示有病例的国家/地区,然后在没有任何数据的日子里将其删除。即使有些日子不见了,我也想保留第一次出现的亮点,但我觉得很难。

merg['Difference'] = np.where(merg.Country_Region == merg.Country_Region.shift(), merg.LastUpdate - merg.LastUpdate.shift(), np.nan)

我创建了一个名为差异的列,用于存储两行日期之间的差异:

fig = px.choropleth(maps, locations="iso_alpha",
                    color="Confirmed", # Confirmed is a column of confirmed cases of maps
                    hover_name="Country_Region", # column to add to hover information
                    animation_frame = "LastUpdate", #LastUpdate is the column of dates
                    color_continuous_scale=['#0d0887', '#46039f', '#7201a8', '#9c179e', '#bd3786', '#d8576b', '#ed7953', '#fb9f3a', '#fdca26', '#f0f921'])
fig.show()

标签: pythonplotlyheatmapchoropleth

解决方案


推荐阅读