index
小部件如何在matplotlib中编写原始的、但与GUI无关的小部件的示例
lasso_selector_demo_sgskip
套索选择器演示使用套索工具以交互方式选择数据点。 此示例绘制散点图。 然后,您可以通过在图表上的点周围绘制套索循环来选择几个点。 要绘制,只需单击图形,按住,然后将其拖动到需要选择的点周围。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import numpy as npfrom matplotlib.widgets import LassoSelectorfrom matplotlib.path import Pathclass SelectFromCollection(object): """Select indices from a matplotlib collection using `LassoSelector`. Selected in...
menu
菜单 输出: 12345100 371 91 29100 342 91 29100 313 91 29100 284 91 29100 255 91 29 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173import ...
multicursor
多光标同时在多个图上显示光标。 此示例生成两个子图,并将光标悬停在一个子图中的数据上,该数据点的值分别显示在两个子图中。 1234567891011121314import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.widgets import MultiCursort = np.arange(0.0, 2.0, 0.01)s1 = np.sin(2*np.pi*t)s2 = np.sin(4*np.pi*t)fig, (ax1, ax2) = plt.subplots(2, sharex=True)ax1.plot(t, s1)ax2.plot(t, s2)multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1)plt.show() 下载这个示例 下载python源码: multicursor.py 下载Jupyter notebook: multicursor.ipynb
polygon_selector_demo
多边形选择器演示显示如何以交互方式选择多边形的索引。 输出: 1234567Select points in the figure by enclosing them within a polygon.Press the 'esc' key to start a new polygon.Try holding the 'shift' key to move all of the vertices.Try holding the 'ctrl' key to move a single vertex.Selected points:[] 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import numpy as npfrom matplotli...
radio_buttons
单选按钮使用单选按钮选择绘图的属性。 单选按钮允许您在可视化中选择多个选项。在这种情况下,按钮允许用户选择要在图中显示的三种不同正弦波中的一种。 1234567891011121314151617181920212223242526272829303132333435363738394041424344import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.widgets import RadioButtonst = np.arange(0.0, 2.0, 0.01)s0 = np.sin(2*np.pi*t)s1 = np.sin(4*np.pi*t)s2 = np.sin(8*np.pi*t)fig, ax = plt.subplots()l, = ax.plot(t, s0, lw=2, color='red')plt.subplots_adjust(left=0.3)axcolor = 'lightgoldenrodyellow'rax = plt.axes...
rectangle_selector
矩形选择器在某处鼠标点击,将鼠标移动到某个目的地,然后释放按钮。 此类提供单击和释放事件,并从点击点到实际鼠标位置(在相同轴内)绘制一条线或一个框,直到释放按钮。 在方法’self.ignore()’中,检查来自eventpress和eventrelease的按钮是否相同。 输出: 1click --> release 123456789101112131415161718192021222324252627282930313233343536373839404142from matplotlib.widgets import RectangleSelectorimport numpy as npimport matplotlib.pyplot as pltdef line_select_callback(eclick, erelease): 'eclick and erelease are the press and release events' x1, y1 = eclick.xdata, eclick.ydata x2,...
slider_demo
滑块演示使用滑块小部件来控制绘图的可视属性。 在此示例中,滑块用于选择正弦波的频率。 您可以通过这种方式控制绘图的许多连续变化属性。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.widgets import Slider, Button, RadioButtonsfig, ax = plt.subplots()plt.subplots_adjust(left=0.25, bottom=0.25)t = np.arange(0.0, 1.0, 0.001)a0 = 5f0 = 3delta_f = 5.0s = a0*np.sin(2*np.pi*f0*t)l, = plt.plot(t, s, lw=2, color='red')plt.axis([0, 1, -10, 10])axcolor = ...
span_selector
跨度选择器SpanSelector是一个鼠标小部件,用于选择xmin / xmax范围并绘制下轴中所选区域的详细视图 1234567891011121314151617181920212223242526272829303132333435363738import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.widgets import SpanSelector# Fixing random state for reproducibilitynp.random.seed(19680801)fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))ax1.set(facecolor='#FFFFCC')x = np.arange(0.0, 5.0, 0.01)y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))ax1.plot(x, y, '-')ax1.set_ylim...
textbox
文本框允许使用Textbox小部件输入文本。 您可以使用“文本框”小部件让用户提供需要显示的任何文本,包括公式。 您可以使用提交按钮创建具有给定输入的绘图。 12345678910111213141516171819202122import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.widgets import TextBoxfig, ax = plt.subplots()plt.subplots_adjust(bottom=0.2)t = np.arange(-2.0, 2.0, 0.001)s = t ** 2initial_text = "t ** 2"l, = plt.plot(t, s, lw=2)def submit(text): ydata = eval(text) l.set_ydata(ydata) ax.set_ylim(np.min(ydata), np.max(ydata)) plt.draw()axbox = plt.axes([0.1...














