Added some text (to be displayed on the bars) in a bar chart with animation frames.
And well, the text instead of rising along with the bar (like in the beginning of the GIF when I manually move the slider), flies in from the top left corner at each frame until the bar is big enough to fit in the number.
Now, tweaking textposition in fig.update_traces() does kinda help. But it limits the text to either inside or outside. The former is not visible in smaller bars at all and the latter imo doesn't look as good as what auto would've looked like without the flying in.
Here is the code to replicate the problem in a smaller dataset-
import pandas as pd
from pandas import Timestamp
import plotly.express as px
df = pd.DataFrame({'continent': {127: 'South America',
128: 'South America',
129: 'South America',
130: 'South America',
131: 'South America',
105: 'Oceania',
106: 'Oceania',
107: 'Oceania',
108: 'Oceania',
109: 'Oceania'},
'date': {127: Timestamp('2021-03-01 00:00:00'),
128: Timestamp('2021-03-26 00:00:00'),
129: Timestamp('2021-04-20 00:00:00'),
130: Timestamp('2021-05-15 00:00:00'),
131: Timestamp('2021-06-09 00:00:00'),
105: Timestamp('2021-03-01 00:00:00'),
106: Timestamp('2021-03-26 00:00:00'),
107: Timestamp('2021-04-20 00:00:00'),
108: Timestamp('2021-05-15 00:00:00'),
109: Timestamp('2021-06-09 00:00:00')},
'total_cases': {127: 20465329.0,
128: 23470911.0,
129: 26544779.0,
130: 29891133.0,
131: 30634559.0,
105: 35923.0,
106: 42208.0,
107: 46514.0,
108: 50183.0,
109: 50805.0}})
px.bar(df, x='continent', y='total_cases', animation_frame=df.date.astype(str), text='total_cases')
