Python:我可以在时间序列等值线中让颜色条保持静态吗?

Python: Can I make the colorbar static in a plotly time series choropleth?

我正在世界地图中随着时间的推移探索 COVID 病例。现在,色标是动态的,最小值和最大值每天都在变化。我想修复它们(可能是 0 和历史最高点),这样我就可以更轻松地相互比较不同的日期。我该怎么做?

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly
from datetime import datetime
import plotly.graph_objs as go
from datetime import timedelta
import plotly.offline as offline
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
df = pd.read_csv('https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/owid-covid-data.csv')

start = datetime.strptime('Jan 1 2020', '%b %d %Y')
df['datum'] = pd.to_datetime(df.date)


df_cleaned = df[df['iso_code'].notna()]
data_slider = []

for datum in df['datum'].unique():
    df_segmented = df_cleaned[df_cleaned['datum']==datum]
    data_each_date = dict(type='choropleth',
                locations = df_segmented['iso_code'],
                z = df_segmented['new_deaths_per_million'],
                
                text = df_segmented['location'],
                colorbar = {'title':'New Deaths per Million'})
    data_slider.append(data_each_date)
 
steps = []
for i in range(len(data_slider)):
    step = dict(method='restyle',
                args=['visible',[False]*len(data_slider)],
                label='Date {}'.format(timedelta(days=1) + start)
                )
    step['args'][1][i]=True
    start = timedelta(days=1) + start
    steps.append(step)


sliders = [dict(active=0, pad={"t": 1}, steps=steps)]

layout = dict(title = 'COVID',
              geo=dict(
                       scope ='world',
                       projection = {'type':'mercator'}
                       ),
              sliders = sliders)

fig =dict(data=data_slider,layout=layout)
plotly.offline.plot(fig)

似乎用max=80zmin=0修复了。我使用此信息作为参考。 How to keep the color bar in a choropleth map consistent with changing data

for datum in df['datum'].unique():
    df_segmented = df_cleaned[df_cleaned['datum']==datum]
    data_each_date = dict(type='choropleth',
                locations = df_segmented['iso_code'],
                z = df_segmented['new_deaths_per_million'],

                zmax = 50, # update
                zmin = 0, # update
                text = df_segmented['location'],
                colorbar = {'title':'New Deaths per Million'})
    data_slider.append(data_each_date)