Reputation: 41
I would like to plot multiple plotly express choropleth maps with their own time sliders next to each other. I have tried lots of different approaches by now, but nothing seems to work. I am aware of of this site from plotly explaining how to plot multiple express plots simultaneously, however, I don't see how I can apply their example without loosing my time animation.
I created a minimal example, including example data:
import pandas as pd
import plotly.express as px
def plot(df):
fig = px.choropleth(df,
locations='region',
locationmode='country names',
color='valence',
hover_name='valence',
animation_frame='date',
projection='natural earth',
color_continuous_scale=px.colors.sequential.Aggrnyl,
range_color=(0, 1))
fig.update_traces(marker_line_width=0)
fig.update_layout(showlegend=False, geo=dict(showframe=False, showcoastlines=False))
fig.update_layout(margin=dict(l=0, r=0, b=0, t=0),
width=1500,
height=800
)
return fig
data_2019 = {
'region': ['Germany', 'Denmark', 'Japan'],
'date': ['2019-01-01', '2019-02-01', '2019-02-01'],
'valence':[0.3, 0.21, 0.1]}
data_2020 = {
'region': ['Germany', 'Denmark', 'Japan'],
'date': ['2020-01-01', '2020-02-01', '2020-02-01'],
'valence':[0.94, 0.71, 0.81]}
df_2019 = pd.DataFrame.from_dict(data_2019)
df_2020 = pd.DataFrame.from_dict(data_2020)
fig_2019 = plot(df_2019)
fig_2020 = plot(df_2020)
My goal is to have the two plots appear next to each other, both with their own time slider, but with only one colorbar on the side.
Upvotes: 0
Views: 80
Reputation: 41
I found a solution, so for anyone in the future, please check my respective post in the plotly forum.
Upvotes: 0