Yoey
Yoey

Reputation: 31

Bubble map animation using python

I try to visualize carbon dioxide data. In order to achieve this bubble animation effect in Python, how could I implement this? I currently use the library of Altair.

bubble effect

Animation link: https://wpivis.github.io/hindsight/demos/co2/

Really appreciated for any suggestions

Upvotes: 2

Views: 442

Answers (1)

joelostblom
joelostblom

Reputation: 48929

This will not be supported in Altair/Vega-Lite until https://github.com/vega/vega/issues/641 is addressed. You might be able to use Plotly animations for this, but I am unsure if they support fading in and out like in your example. It seems like you could also use matplotlib for a similar effect, like what is suggested in this blog post:

from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
import random
import numpy as np
  
x = []
y = []
colors = []
fig = plt.figure(figsize=(7,5))
  
def animation_func(i):
    x.append(random.randint(0,100))
    y.append(random.randint(0,100))
    colors.append(np.random.rand(1))
    area = random.randint(0,30) * random.randint(0,30)
    plt.xlim(0,100)
    plt.ylim(0,100)
    plt.scatter(x, y, c = colors, s = area, alpha = 0.5)
  
animation = FuncAnimation(fig, animation_func, 
                          interval = 100)
plt.show()

Upvotes: 2

Related Questions