解决pycharm的matplotlib不显示动图问题

1. 问题:绘制图自动转化为png

或者显示空白

fda303a611a249efa6ede018ad51fcaa.png

2. 解决过程

2.1. 打开设置

5fdf11699a82480d934b1ca5984564a3.png

2.2. 取消勾选

在tool里找到plot,或者直接搜索,取消勾选Show plots in tool Windows

66f4d8c9d74d4ca0be5aed9327560097.png

3. 最后成功显示

不再是侧面的工具栏,而是单独形成一个窗口

d4cac8dda54646bca4c98fcb8a3b2190.png

cbeaf76168a34d62909f584d6e3cbede.gif

 4.代码

 代码借鉴官网:
Animated scatter saved as GIF — Matplotlib 3.10.0 documentation

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.animation as animation

fig, ax = plt.subplots()
ax.set_xlim([0, 10])

scat = ax.scatter(1, 0)
x = np.linspace(0, 10)


def animate(i):
    scat.set_offsets((x[i], 0))
    return (scat,)


ani = animation.FuncAnimation(fig, animate, repeat=True, frames=len(x) - 1, interval=50)

# To save the animation using Pillow as a gif
writer = animation.PillowWriter(fps=15,
                                metadata=dict(artist='Me'),
                                bitrate=1800)
ani.save('scatter.gif', writer=writer)

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值