我试着把二氧化碳数据可视化。为了在Python中实现这种气泡动画效果,我如何实现它?我现在使用的是牛郎星图书馆。
动画链接:https://wpivis.github.io/hindsight/demos/co2/
真的很感谢你的建议
发布于 2022-04-29 23:17:28
在解决https://github.com/vega/vega/issues/641之前,Altair/Vega将不支持这一点。您可能会为此使用真实的动画,但我不确定它们是否支持像您的示例中那样的渐变。似乎您也可以使用matplotlib实现类似的效果,如这篇博客文章中所建议的那样。
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()

https://stackoverflow.com/questions/72064342
复制相似问题