membrane
Frontpage 绘图示例此示例再现Frontpage 绘图示例。 12345678910111213141516import matplotlib.pyplot as pltimport matplotlib.cbook as cbookimport numpy as npwith cbook.get_sample_data('membrane.dat') as datafile: x = np.fromfile(datafile, np.float32)# 0.0005 is the sample intervalfig, ax = plt.subplots()ax.plot(x, linewidth=4)ax.set_xlim(5000, 6000)ax.set_ylim(-0.6, 0.1)ax.set_xticks([])ax.set_yticks([])fig.savefig("membrane_frontpage.png", dpi=25) # results in 160x120 px image 下载这个示例...
coords_demo
Coords 演示如何通过连接到移动和单击事件来与绘图画布交互的示例 1234567891011121314151617181920212223242526272829303132333435import sysimport matplotlib.pyplot as pltimport numpy as npt = np.arange(0.0, 1.0, 0.01)s = np.sin(2 * np.pi * t)fig, ax = plt.subplots()ax.plot(t, s)def on_move(event): # get the x and y pixel coords x, y = event.x, event.y if event.inaxes: ax = event.inaxes # the axes instance print('data coords %f %f' % (event.xdata, event.ydata))def on_click(event): # get t...
close_event
关闭事件显示图形关闭时发生的连接事件的示例。 1234567891011import matplotlib.pyplot as pltdef handle_close(evt): print('Closed Figure!')fig = plt.figure()fig.canvas.mpl_connect('close_event', handle_close)plt.text(0.35, 0.5, 'Close Me!', dict(size=30))plt.show() 下载这个示例 下载python源码: close_event.py 下载Jupyter notebook: close_event.ipynb
data_browser
数据浏览器在多个画布之间连接数据。 此示例介绍了如何与多个画布交互数据。这样,您可以选择并突出显示一个轴上的点,并在另一个轴上生成该点的数据。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990import numpy as npclass PointBrowser(object): """ Click on a point to select and highlight it -- the data that generated the point will be shown in the lower axes. Use the 'n' and 'p' keys to browse throug...
ginput_demo_sgskip
Ginput 演示这提供了交互功能的使用示例,例如ginput。 12345678import matplotlib.pyplot as pltimport numpy as npt = np.arange(10)plt.plot(t, np.sin(t))print("Please click")x = plt.ginput(3)print("clicked", x)plt.show() 下载这个示例 下载python源码: ginput_demo_sgskip.py 下载Jupyter notebook: ginput_demo_sgskip.ipynb
figure_axes_enter_leave
图轴的进入和离开通过更改进入和离开时的框架颜色来说明图形和轴进入和离开事件 12345678910111213141516171819202122232425import matplotlib.pyplot as pltdef enter_axes(event): print('enter_axes', event.inaxes) event.inaxes.patch.set_facecolor('yellow') event.canvas.draw()def leave_axes(event): print('leave_axes', event.inaxes) event.inaxes.patch.set_facecolor('white') event.canvas.draw()def enter_figure(event): print('enter_figure', event.canvas.figure) event.ca...
image_slices_viewer
图像切片查看器滚动三维阵列的二维图像切片。 123456789101112131415161718192021222324252627282930313233343536373839import numpy as npimport matplotlib.pyplot as pltclass IndexTracker(object): def __init__(self, ax, X): self.ax = ax ax.set_title('use scroll wheel to navigate images') self.X = X rows, cols, self.slices = X.shape self.ind = self.slices//2 self.im = ax.imshow(self.X[:, :, self.ind]) self.update() def onscroll(self, event): print(&q...
ginput_manual_clabel_sgskip
交互功能这提供了交互功能的使用示例,例如ginput,waitforbuttonpress和手动clabel放置。 必须使用具有图形用户界面的后端以交互方式运行此脚本(例如,使用GTK3Agg后端,而不是PS后端)。 另见: ginput_demo.py 12345678910import timeimport numpy as npimport matplotlib.pyplot as pltdef tellme(s): print(s) plt.title(s, fontsize=16) plt.draw() 单击三个点定义三角形 123456789101112131415161718192021222324252627plt.clf()plt.axis([-1., 1., -1., 1.])plt.setp(plt.gca(), autoscale_on=False)tellme('You will define a triangle, click to begin')plt.waitforbuttonpress()while Tru...
index
事件处理Matplotlib支持使用GUI中立事件模型进行事件处理,因此您可以连接到Matplotlib事件,而无需了解Matplotlib最终将插入哪个用户界面。 这有两个好处:你编写的代码将更加可移植,Matplotlib事件就像数据坐标空间和事件发生在哪些轴之类的东西,所以你不必混淆低级转换细节来自画布空间到数据空间。还包括对象拾取示例。
keypress_demo
按键演示显示如何连接到按键事件 12345678910111213141516171819202122232425import sysimport numpy as npimport matplotlib.pyplot as pltdef press(event): print('press', event.key) sys.stdout.flush() if event.key == 'x': visible = xl.get_visible() xl.set_visible(not visible) fig.canvas.draw()# Fixing random state for reproducibilitynp.random.seed(19680801)fig, ax = plt.subplots()fig.canvas.mpl_connect('key_press_event', press)ax.plot(np.random.rand(12),...













