It doesn’t matter if subsequent frames contain the data or not, it seems like having a value for X and Y for the first frame is a primary determinant if the bubble continues to show up in subsequent frames.
If a data has an X,Y value for the first frame, it doesn’t matter if there are no values in subsequent frames, they still get their own name listed on the legend.
Example:
temp = saas.copy()
temp = temp.fillna(0)
temp = temp[temp['symbol'].isin(tickers[:10])]
temp = temp[~temp['quarter'].isin(['17Q4', '22Q3', '22Q2', '22Q1', '18Q1', '18Q2', '18Q3'])]
temp = temp.sort_values('quarter', ascending = True)
color_discrete= {
'VEEV': 'black',
'ZS': 'grey',
'INTU': 'blue',
'TWLO': 'darkblue',
'TEAM': 'green',
'SHOP': 'darkgreen',
'ADBE': 'red',
'ZM': 'lightblue',
'DDOG': 'purple',
'CRM': 'firebrick'
}
fig = px.scatter(
temp,
x= 'Revenue Y/Y',
y= 'Revenue Multiple',
animation_frame="quarter",
animation_group="symbol",
size="Market Cap",
color= 'symbol',
hover_name='symbol',
size_max=120,
range_x=[-20,200],
range_y=[0, 60],
color_discrete_map= color_discrete
)
fig.update_layout(
title= dict(
text= 'Bubble',
font= {'size': 14,
'color': 'red',},
x= 0.1,
),
xaxis=dict(
title='Revenue Growth Y/Y %',
),
yaxis=dict(
title='P/S Ratio',
),
showlegend = True,
height= 600,
width= 800,
)
fig.show()
Example 1:
If I do not truncate the period to ensure all color variable contains XY data in first frame.
#temp = temp[~temp['quarter'].isin(['17Q4', '22Q3', '22Q2', '22Q1', '18Q1', '18Q2', '18Q3'])]
Currently, the only workaround I know for this problem is to create a 0th time period for each categorical variable (that will be used for color) and fill them with dummy X & Y values for the animation to work as intended.
But this isn’t a long-term solution and not scalable if the number of variables within color category increases to 20+.
Would love to hear a good fix or solution to this problem.