本文主要是介绍今天把 MATPLOTLIB的动态散点图代码 读懂了,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码如下:
心得后附。
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as npclass AnimatedScatter(object):
"""An animated scatter plot using matplotlib.animations.FuncAnimation."""
def __init__(self, numpoints=50):
self.numpoints = numpoints
self.stream = self.data_stream() # Setup the figure and axes...
self.fig, self.ax = plt.subplots()
# Then setup FuncAnimation.
self.ani = animation.FuncAnimation(self.fig, self.update, interval=5,
init_func=self.setup_plot, blit=True) def setup_plot(self):
"""Initial drawing of the scatter plot."""
x, y, s, c = next(self.stream)
self.scat = self.ax.scatter(x, y, c=c, s=s, animated=True)
self.ax.axis([-10, 10, -10, 10]) # For FuncAnimation's sake, we need to return the artist we'll be using
# Note that it expects a sequence of art
这篇关于今天把 MATPLOTLIB的动态散点图代码 读懂了的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!