lasso_demo
套索演示演示如何使用套索选择一组点并获取所选点的索引。回调用于更改所选点的颜色。 这是一个概念验证实现(尽管它可以按原样使用)。将对API进行一些改进。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677from matplotlib import colors as mcolors, pathfrom matplotlib.collections import RegularPolyCollectionimport matplotlib.pyplot as pltfrom matplotlib.widgets import Lassoimport numpy as npclass Datum(object): colorin = mcolors.to_rgba("red") colorout = mcolor...
legend_picking
图例选择启用图例上的拾取以打开和关闭原始线。 123456789101112131415161718192021222324252627282930313233343536373839404142import numpy as npimport matplotlib.pyplot as pltt = np.arange(0.0, 0.2, 0.1)y1 = 2*np.sin(2*np.pi*t)y2 = 4*np.sin(2*np.pi*2*t)fig, ax = plt.subplots()ax.set_title('Click on legend line to toggle line on/off')line1, = ax.plot(t, y1, lw=2, color='red', label='1 HZ')line2, = ax.plot(t, y2, lw=2, color='blue', label='2 HZ')leg = ax.legend(loc='...
looking_glass
镜子例如,使用鼠标事件模拟用于检查数据的镜子。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import numpy as npimport matplotlib.pyplot as pltimport matplotlib.patches as patches# Fixing random state for reproducibilitynp.random.seed(19680801)x, y = np.random.rand(2, 200)fig, ax = plt.subplots()circ = patches.Circle((0.5, 0.5), 0.25, alpha=0.8, fc='yellow')ax.add_patch(circ)ax.plot(x, y, alpha=0.2)line, = ax.plot(x, y, alpha=1.0, clip_path=circ)ax.set_titl...
path_editor
路径编辑器跨GUI共享事件。 此示例演示了使用Matplotlib事件处理与画布上的对象进行交互和修改对象的跨GUI应用程序。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149import numpy as npimport matplotlib.path as mpathimport matplotlib.patches as mpatchesimport ...
pick_event_demo
选择事件演示您可以通过设置艺术家的“选择器”属性来启用拾取(例如,matplotlib Line2D,Text,Patch,Polygon,AxesImage等…) 选择器属性有多种含义 None - 此艺术家对象的选择功能已停用(默认) boolean - 如果为True,则启用拾取,如果鼠标事件在艺术家上方,艺术家将触发拾取事件 float - 如果选择器是一个数字,则它被解释为以点为单位的epsilon容差,如果事件的数据在鼠标事件的epsilon内,则艺术家将触发事件。 对于某些艺术家(如线条和补丁集合),艺术家可能会为生成的挑选事件提供其他数据,例如,挑选事件的epsilon中的数据索引 function - 如果选择器是可调用的,则它是用户提供的函数,用于确定艺术家是否被鼠标事件命中。 hit, props = picker(artist, mouseevent) 确定命中测试。 如果鼠标事件在艺术家上方,则返回hit = True,props是要添加到PickEvent属性的属性字典 通过设置“选取器”属性启用艺术家进行拾取后...
pick_event_demo2
选择事件演示2计算100个数据集的平均值和标准差(stddev),并绘制平均值vs stddev。单击其中一个mu,sigma点时,绘制生成均值和stddev的数据集中的原始数据。 12345678910111213141516171819202122232425262728293031323334import numpy as npimport matplotlib.pyplot as pltX = np.random.rand(100, 1000)xs = np.mean(X, axis=1)ys = np.std(X, axis=1)fig, ax = plt.subplots()ax.set_title('click on point to plot time series')line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerancedef onpick(event): if event.artist != line: return True ...
poly_editor
综合编辑器这是一个示例,展示如何使用Matplotlib事件处理来构建跨GUI应用程序,以与画布上的对象进行交互。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174import numpy as npfrom m...
pipong
Pipong一个基于Matplotlib的Pong游戏,说明了一种编写交互动画的方法,它很容易移植到多个后端pipong.py由Paul Ivanov撰写http://pirsquared.org 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816...
pong_sgskip
Pong一个使用Matplotlib的小游戏演示。 此示例需要pipong.py 1234567891011121314151617181920212223242526272829303132333435363738394041import timeimport matplotlib.pyplot as pltimport pipongfig, ax = plt.subplots()canvas = ax.figure.canvasanimation = pipong.Game(ax)# disable the default key bindingsif fig.canvas.manager.key_press_handler_id is not None: canvas.mpl_disconnect(fig.canvas.manager.key_press_handler_id)# reset the blitting background on redrawdef handle_redraw(event): animation.background = None...
timers
计时器使用通用计时器对象的简单示例。这用于更新图中标题的时间。 123456789101112131415161718192021222324252627import matplotlib.pyplot as pltimport numpy as npfrom datetime import datetimedef update_title(axes): axes.set_title(datetime.now()) axes.figure.canvas.draw()fig, ax = plt.subplots()x = np.linspace(-3, 3)ax.plot(x, x ** 2)# Create a new timer object. Set the interval to 100 milliseconds# (1000 is default) and tell the timer what function should be called.timer = fig.canvas.new_timer(interval=100)timer.add_call...














