使用Python的气泡图动画

发布于 2025-01-25 02:14:17 字数 369 浏览 6 评论 0原文

我尝试可视化二氧化碳数据。为了在Python中实现这种泡沫动画效应,我该如何实现?我目前使用Altair图书馆。

泡泡效应

动画链接: https://wpivis.github.io/hindsight/hindsight/demos/co2/

非常感谢任何建议

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御弟哥哥 2025-02-01 02:14:17

直到 https://github.com/vaub.com/vaga/ Vega/essue/641 已解决。您也许可以使用 Plotly Animations 为此像你的示例一样。看来您也可以使用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()

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()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文