Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Bubble plot is stuck in one year

I am making an animated bubble plot that is almost done but, when it runs it comes across a problem. That is being stuck in the middle of my graph. I am trying to graph the amount of pesticide used in relation to the year.

figure = bubbleplot(dataset=df.sort_values('year'), 
    x_column='year', y_column='nCLOTHIANIDIN',
    bubble_column='nCLOTHIANIDIN', time_column='year', 
    size_column='nCLOTHIANIDIN', color_column='nCLOTHIANIDIN',
    x_title="year", y_title="nCLOTHIANIDIN", 
    title='Timeline of honey production for each state in USA', 
    colorbar_title='# colonies', colorscale='Viridis', 
    x_logscale=False, y_logscale=False, scale_bubble=1.8, 
    height=650) 
iplot(figure, config={'scrollzoom': True})

Which provides this:


Now when I run the code it iterates through the slider perfectly but, as you can see for some reason the x axis is all messed up. It starts at 1500 and ends at 2500 for some reason when it should have the same years as the slider. Also as you can tell the bubbles are stuck at 2000. I don’t know why. Thanks for the help.

Hi @iiWylde,

I think what might be happening here is that plotly is automatically computing the xaxis range based on the location and size of the markers. But the top markers are so large that (looks like a diameter of 1000 years or so) that the auto range is much larger than you want. I think this is why it looks like the x-values are constant, because the plot is zoomed out so far in the x-dimension.

I’d recommend two changes.

  1. Set the layout.xaxis.range value explicitly to the range you want, this will disable to auto range logic. and keep a fixed interval during the animation. Maybe a range of [1985, 2020] in your case.
  2. Scale down your size column until the markers fit comfortable inside that range. Maybe start by dividing size by 1000 and adjust from there.

Hope that helps!
-Jon

1 Like

Got it working! Thank you!

1 Like