resample
重采样数据下采样会降低信号的采样率或采样大小。在本教程中,当通过拖动和缩放调整打印时,将对信号进行缩减采样。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import numpy as npimport matplotlib.pyplot as plt# A class that will downsample the data and recompute when zoomed.class DataDisplayDownsampler(object): def __init__(self, xdata, ydata): self.origYData = ydata self.origXData = xdata self.max_points = 50 self.delta = xdata[-1] - xdata[0] def down...
trifinder_event_demo
Trifinder 事件演示显示使用TriFinder对象的示例。当鼠标在三角测量上移动时,光标下方的三角形将突出显示,三角形的索引将显示在图表标题中。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import matplotlib.pyplot as pltfrom matplotlib.tri import Triangulationfrom matplotlib.patches import Polygonimport numpy as npdef update_polygon(tri): if tri == -1: points = [0, 0, 0] else: points = triang.triangles[tri] xs = triang.x[points] ys = triang.y[points] polygon.set_xy(np.column_stac...
zoom_window
缩放窗口此示例显示如何将一个窗口(例如鼠标按键)中的事件连接到另一个体形窗口。 如果单击第一个窗口中的某个点,将调整第二个窗口的z和y限制,以便第二个窗口中缩放的中心将是所单击点的x,y坐标。 请注意,散点图中圆的直径以点**2定义,因此它们的大小与缩放无关。 123456789101112131415161718192021222324252627import matplotlib.pyplot as pltimport numpy as npfigsrc, axsrc = plt.subplots()figzoom, axzoom = plt.subplots()axsrc.set(xlim=(0, 1), ylim=(0, 1), autoscale_on=False, title='Click to zoom')axzoom.set(xlim=(0.45, 0.55), ylim=(0.4, 0.6), autoscale_on=False, title='Zoom window')x, y,...
viewlims
Viewlims创建两个相同的面板。在右侧面板上放大将在第一个面板中显示一个矩形,表示缩放的区域。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.patches import Rectangle# We just subclass Rectangle so that it can be called with an Axes# instance, causing the rectangle to update its shape to match the# bounds of the Axesclass UpdatingRect(Rectangle): def __call__(self, ax): ...
affine_image
图像的仿射变换将仿射变换(Affine2D)预先添加到图像的数据变换允许操纵图像的形状和方向。这是变换链的概念的一个例子。 对于支持具有可选仿射变换的draw_image的后端(例如,agg,ps后端),输出的图像应该使其边界与虚线黄色矩形匹配。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import numpy as npimport matplotlib.pyplot as pltimport matplotlib.transforms as mtransformsdef get_image(): delta = 0.25 x = y = np.arange(-3.0, 3.0, delta) X, Y = np.meshgrid(x, y) Z1 = np.exp(-X**2 - Y**2) Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2) Z = (Z1 - Z2) re...
barb_demo
倒勾图示例倒勾图的示例: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546import matplotlib.pyplot as pltimport numpy as npx = np.linspace(-5, 5, 5)X, Y = np.meshgrid(x, x)U, V = 12 * X, 12 * Ydata = [(-1.5, .5, -6, -6), (1, -1, -46, 46), (-3, -1, 11, -11), (1, 1.5, 80, 80), (0.5, 0.25, 25, 15), (-1.5, -0.5, -5, 40)]data = np.array(data, dtype=[('x', np.float32), ('y', np.float32), ('...
barcode_demo
条形码示例该演示展示了如何生成一维图像或“条形码”。 12345678910111213141516171819202122232425import matplotlib.pyplot as pltimport numpy as np# Fixing random state for reproducibilitynp.random.seed(19680801)# the barx = np.where(np.random.rand(500) > 0.7, 1.0, 0.0)axprops = dict(xticks=[], yticks=[])barprops = dict(aspect='auto', cmap=plt.cm.binary, interpolation='nearest')fig = plt.figure()# a vertical barcodeax1 = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)ax1.imshow(x.reshape((-1, 1)), **b...
contour_demo
等高线演示演示简单的等高线绘制,图像上的等高线带有等高线的颜色条,并标出等高线。 另见轮廓图像示例。 12345678910111213import matplotlibimport numpy as npimport matplotlib.cm as cmimport matplotlib.pyplot as pltdelta = 0.025x = np.arange(-3.0, 3.0, delta)y = np.arange(-2.0, 2.0, delta)X, Y = np.meshgrid(x, y)Z1 = np.exp(-X**2 - Y**2)Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)Z = (Z1 - Z2) * 2 使用默认颜色创建带有标签的简单等高线图。clabel的内联参数将控制标签是否画在轮廓的线段上,移除标签下面的线。 1234fig, ax = plt.subplots()CS = ax.contour(X, Y, Z)ax.clabel(CS, inline=1, fontsize=10)ax.set_title...
contour_image
等高线图像等高线,填充等高线和图像绘制的测试组合。 有关等高线标记,另请参见等高线演示示例。 本演示的重点是展示如何在图像上正确展示等高线,以及如何使两者按照需要定向。 特别要注意 “origin”和“extent” 关键字参数在imshow和contour中的用法。 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import cm# Default delta is large because that makes it fast, and it illustrates# the correct registration between image and contours.delta = 0.5e...
contour_corner_mask
等高线角遮盖此示例中显示了以下函数,方法和类的使用: 123456789101112131415161718192021222324252627282930import matplotlib.pyplot as pltimport numpy as np# Data to plot.x, y = np.meshgrid(np.arange(7), np.arange(10))z = np.sin(0.5 * x) * np.cos(0.52 * y)# Mask various z values.mask = np.zeros_like(z, dtype=bool)mask[2, 3:5] = Truemask[3:5, 4] = Truemask[7, 2] = Truemask[5, 0] = Truemask[0, 6] = Truez = np.ma.array(z, mask=mask)corner_masks = [False, True]fig, axs = plt.subplots(ncols=2)for ax, corner_mask in zip(axs, c...














