animation_demo
pyplot动画通过调用绘图命令之间的暂停来生成动画。 此处显示的方法仅适用于简单,低性能的使用。 对于要求更高的应用程序,请查看动画模块和使用它的示例。 请注意,调用time.sleep而不是暂停将不起作用。 1234567891011121314import matplotlib.pyplot as pltimport numpy as npnp.random.seed(19680801)data = np.random.random((50, 50, 50))fig, ax = plt.subplots()for i in range(len(data)): ax.cla() ax.imshow(data[i]) ax.set_title("frame {}".format(i)) # Note that using time.sleep does *not* work here! plt.pause(0.1) 脚本总运行时间:(0分7.211秒) 下载这个示例 下载python源码: animati...
bayes_update
贝叶斯更新此动画显示在新数据到达时重新安装的后验估计更新。 垂直线表示绘制的分布应该收敛的理论值。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import mathimport numpy as npimport matplotlib.pyplot as pltfrom matplotlib.animation import FuncAnimationdef beta_pdf(x, a, b): return (x**(a-1) * (1-x)**(b-1) * math.gamma(a + b) / (math.gamma(a) * math.gamma(b)))class UpdateDist(object): def __init__(self, ax, prob=0.5): self.success = 0 self.prob = prob ...
dynamic_image
使用预先计算的图像列表的动画图像 123456789101112131415161718192021222324252627282930313233343536import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animationfig = plt.figure()def f(x, y): return np.sin(x) + np.cos(y)x = np.linspace(0, 2 * np.pi, 120)y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)# ims is a list of lists, each row is a list of artists to draw in the# current frame; here we are just animating one artist, the image, in# each frameims = []for i in range(60): x...
double_pendulum_sgskip
双摆问题这个动画说明了双摆问题。 双摆公式从 http://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c 的C代码翻译而来。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586from numpy import sin, cosimport numpy as npimport matplotlib.pyplot as pltimport scipy.integrate as integrateimport matplotlib.animation as animationG = 9.8 # acceleration due to gravity, in m/s^2L1 = 1.0 # length of pendulum 1 in mL2...
frame_grabbing_sgskip
帧抓取直接使用MovieWriter抓取单个帧并将其写入文件。 这避免了任何事件循环集成,因此甚至可以与Agg后端一起使用。 建议不要在交互式设置中使用。 12345678910111213141516171819202122232425262728import numpy as npimport matplotlibmatplotlib.use("Agg")import matplotlib.pyplot as pltfrom matplotlib.animation import FFMpegWriter# Fixing random state for reproducibilitynp.random.seed(19680801)metadata = dict(title='Movie Test', artist='Matplotlib', comment='Movie support!')writer = FFMpegWriter(fps=15, metadata...
rain
雨模拟通过设置50个散点的比例和不透明度来模拟表面上的雨滴。 作者:Nicolas P. Rougier 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.animation import FuncAnimation# Fixing random state for reproducibilitynp.random.seed(19680801)# Create new Figure and an Axes which fills it.fig = plt.figure(figsize=(7, 7))ax = fig.add_axes([0, 0, 1, 1], frameon=False)ax.set_xlim(0, 1), ax.set_xticks([])ax.set_ylim...
random_walk
动画3D随机游走 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import numpy as npimport matplotlib.pyplot as pltimport mpl_toolkits.mplot3d.axes3d as p3import matplotlib.animation as animation# Fixing random state for reproducibilitynp.random.seed(19680801)def Gen_RandLine(length, dims=2): """ Create a line using a random walk algorithm length is the number of points for the line. dims is the number of...
simple_anim
动画线图 12345678910111213141516171819202122232425262728293031323334import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animationfig, ax = plt.subplots()x = np.arange(0, 2*np.pi, 0.01)line, = ax.plot(x, np.sin(x))def init(): # only required for blitting to give a clean slate. line.set_ydata([np.nan] * len(x)) return line,def animate(i): line.set_ydata(np.sin(x + i / 100)) # update the data. return line,ani = animation.FuncAnimation( fig, animate, init_...
unchained
MATPLOTLIB UNCHAINED脉冲星的假信号频率的比较路径演示(主要是因为Joy Division的未知乐趣的封面而闻名)。 作者:Nicolas P. Rougier 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation# Fixing random state for reproducibilitynp.random.seed(19680801)# Create new Figure with black backgroundfig = plt.figure(figsize=(8, 8), facecolor='black')# Add a subplot with no frameax = p...
axis_direction_demo_step01
轴方向演示步骤01 1234567891011121314151617181920212223242526import matplotlib.pyplot as pltimport mpl_toolkits.axisartist as axisartistdef setup_axes(fig, rect): ax = axisartist.Subplot(fig, rect) fig.add_axes(ax) ax.set_ylim(-0.1, 1.5) ax.set_yticks([0, 1]) ax.axis[:].set_visible(False) ax.axis["x"] = ax.new_floating_axis(1, 0.5) ax.axis["x"].set_axisline_style("->", size=1.5) return axfig = plt.figure(figsize=(3, 2.5))fig.subplots_adjust(top...














