以下数据集需要以年份作为气泡图.随着年份的推移,预期生命周期 (X轴)和GDP(Y轴)需要改变.

df.head()

enter image description here

下图为1960年:

enter image description here

下图为1961年:

enter image description here

我的要求是绘制预期生命周期 与GDP的关系图以及年份.

fig, ax = plt.subplots()

s = ax.scatter([], [])

def animate_(i):

    # clear the axis each frame
    ax.clear()
    
    # replot things
    s = ax.scatter("LifeExpectency",
                   "GDP_in_log2",
                   alpha=0.5,
                   s='population',
                   c='colorForContinent',
                  data = df)
    return s,

anim = FuncAnimation(fig, animate_, frames = 62 , interval=500, blit=False)

#anim.save('Countries progression.mp4')

Following the image i got. It means all the year output merge one another. Any idea how to sort this out. enter image description here

推荐答案

您需要通过过滤dfanimate_中的iYear联系起来

试试df[df['Year'] == some_function(i)]

其中some_function(i)将帧计数映射到所选年份

Python相关问答推荐

七段显示不完整

在IIS中运行的FastAPI-获取权限错误:[Win错误10013]试图以其访问权限禁止的方式访问插槽

正在设置字段.需要为假,因为错误列表索引必须是整数或切片,而不是字符串

如何将uint 16表示为float 16

是否有方法将现有的X-Y图转换为X-Y-Y1图(以重新填充)?

Polars -转换为PL后无法计算熵.列表

"Discord机器人中缺少所需的位置参数ctx

用Python获取HTML Span类中的数据

过滤绕轴旋转的螺旋桨

Python Hashicorp Vault库hvac创建新的秘密版本,但从先前版本中删除了密钥

当密钥是复合且唯一时,Pandas合并抱怨标签不唯一

Locust请求中的Python和参数

Python 约束无法解决n皇后之谜

输出中带有南的亚麻神经网络

将数据框架与导入的Excel文件一起使用

梯度下降:简化要素集的运行时间比原始要素集长

python中字符串的条件替换

从嵌套的yaml创建一个嵌套字符串,后面跟着点

如何在turtle中不使用write()来绘制填充字母(例如OEG)

python中的解释会在后台调用函数吗?