问题描述
我正在尝试在Jupyter笔记本上绘制散点图。每当我尝试创建一个图时,它都会短暂显示一个图,然后“崩溃”。
xx =[1,2,3]
yy = [1,3]
fig2,ax2 = plt.subplots()
ax2.set_xlim(0,10)
ax2.set_ylim(0,10)
sc = ax2.scatter(xx,yy)
plt.show()
这些是我的进口商品,如果可以帮助找到解决方案,我将matplotlib设置为内联
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import FuncAnimation
%matplotlib notebook
编辑
当我重新启动内核时,这对我有用,但是,当我尝试设置动画时,它不起作用
这是我的动画代码
class Particle:
def __init__(self,x,y):
self.x = x
self.y = y
self.velX = 0
self.velY = 5
self.acc = 0.5
def updateValues(self):
self.x = self.x + self.velX
self.y = self.y + self.velY
self.velY = self.velY - self.acc
xData = []
yData = []
globX = []
globY = []
fig,ax = plt.subplots()
ax.set_xlim(0,400)
ax.set_ylim(0,80)
sc = ax.scatter(x=globX,y=globY)
#create a particle
p = Particle(40,0)
def animationFrame2(ii,globX,globY,part):
part.updateValues()
xData.append(part.x)
yData.append(part.y)
globX.append(part.x)
globY.append(part.y)
sc.set_offsets(([globX,globY]))
return sc,animation = FuncAnimation(fig,func=animationFrame2,frames=10,interval=1000,fargs=(globX,p),repeat=True)
plt.show()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)