image_clip_path
使用补丁剪切图像演示的图像,已被一个圆形补丁裁剪。 123456789101112131415import matplotlib.pyplot as pltimport matplotlib.patches as patchesimport matplotlib.cbook as cbookwith cbook.get_sample_data('grace_hopper.png') as image_file: image = plt.imread(image_file)fig, ax = plt.subplots()im = ax.imshow(image)patch = patches.Circle((260, 200), radius=200, transform=ax.transData)im.set_clip_path(patch)ax.axis('off')plt.show() 参考下面的示例演示了以下函数和方法的使用: 1234import matplotlibmatplotlib.axes.Axes.imshowm...
image_nonuniform
不均匀分布图像这说明了非统一图像类。它不是通过AXES方法提供的,但是可以很容易地将它添加到AXIS实例中,如下所示。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.image import NonUniformImagefrom matplotlib import cminterp = 'nearest'# Linear x array for cell centers:x = np.linspace(-4, 4, 9)# Highly nonlinear x array:x2 = x**3y = np.linspace(-4, 4, 9)z = np.sqrt(x[np.newaxis, :]**2 + y[:, np.newaxis]**2)fig, axs ...
image_transparency_blend
在二维图像中混合透明和颜色混合透明与颜色,以突出显示部分数据与显示。 matplotlib.pyplot.imshow()的一个常见用途是绘制二维统计图。虽然imshow可以很容易地将二维矩阵可视化为图像,但它并不容易让您为输出添加透明度。例如,可以绘制统计量(例如t统计量)并根据其p值为每个像素的透明度着色。此示例演示如何使用matplotlib.colors.Normalize实现此效果。 请注意,无法直接将alpha值传递给matplotlib.pyplot.imshow()。 首先我们将生成一些数据,在这种情况下,我们将在二维网格中创建两个2维“blob”。一个blob是正面的,另一个是负面的。 1234567891011121314151617181920212223242526272829303132333435363738394041424344# sphinx_gallery_thumbnail_number = 3import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.colors imp...
irregulardatagrid
不规则空间数据的等高线图不规则空间数据在规则网格上插值的等高线图与非结构三角形网格的三棱图的比较。 由于 contour 和 contourf 期望数据存在于规则网格上,因此绘制不规则间隔数据的等高线图需要不同的方法。这两个选项是: 首先将数据插值到常规网格。这可以通过机载装置完成,例如,通过LinearTriInterpolator或使用外部功能,例如 通过scipy.interpolate.griddata。然后用常规的等高线绘制插值数据。 直接使用tricontour或tricontourf,它将在内部进行三角测量。 此示例显示了两种方法。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import matplotlib.pyplot as pltimport matplotlib.tri as triimport numpy as npnp.random.seed(19680801)...
matshow
Matshow简单的 matshow 例子。 12345678910111213141516import matplotlib.pyplot as pltimport numpy as npdef samplemat(dims): """Make a matrix with all zeros and increasing elements on the diagonal""" aa = np.zeros(dims) for i in range(min(dims)): aa[i, i] = i return aa# Display matrixplt.matshow(samplemat((15, 15)))plt.show() 参考此示例中显示了以下函数和方法的用法: 123import matplotlibmatplotlib.axes.Axes.matshowmatplotlib.pyplot.matshow 下载这个示例 下载python源码: matshow.py 下...
image_zcoord
修改坐标格式化程序修改坐标格式化程序,以报告给定x和y的最近像素的图像“z”值。这个功能在默认情况下是内置的,但是展示如何自定义Format_coord函数仍然很有用。 1234567891011121314151617181920212223242526import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)X = 10*np.random.rand(5, 3)fig, ax = plt.subplots()ax.imshow(X, interpolation='nearest')numrows, numcols = X.shapedef format_coord(x, y): col = int(x + 0.5) row = int(y + 0.5) if col >= 0 and col < numcols and row >= 0 and row ...
interpolation_methods
imshow或matshow的插值这个示例显示了imshow() 和matshow()的插值方法之间的区别。 如果插值为无,则默认为图像。插值RC参数。如果插值是 “none” ,则不执行插值的Agg,ps和pdf后端。其他后端将默认为“nearest”。 对于Agg、ps和pdf后端,当大图像缩小时,interpolation = 'none' 工作得很好,而当小图像被放大时,interpolation = 'interpolation = 'none' 则运行正常。 1234567891011121314151617181920212223import matplotlib.pyplot as pltimport numpy as npmethods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36...
layer_images
图层图像使用Alpha混合将图像层叠在彼此之上 1234567891011121314151617181920212223242526272829303132333435import matplotlib.pyplot as pltimport numpy as npdef func3(x, y): return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2 + y**2))# make these smaller to increase the resolutiondx, dy = 0.05, 0.05x = np.arange(-3.0, 3.0, dx)y = np.arange(-3.0, 3.0, dy)X, Y = np.meshgrid(x, y)# when layering multiple images, the images need to have the same# extent. This does not mean they need to have the same shape, but# they b...
multi_image
多重图像用单一的彩色地图、标准和颜色条制作一组图像。 123456789101112131415161718192021222324252627282930313233343536373839404142434445from matplotlib import colorsimport matplotlib.pyplot as pltimport numpy as npnp.random.seed(19680801)Nr = 3Nc = 2cmap = "cool"fig, axs = plt.subplots(Nr, Nc)fig.suptitle('Multiple images')images = []for i in range(Nr): for j in range(Nc): # Generate data with a range that varies from one plot to the next. data = ((1 + i + j) / 10) * np.random.rand(1...
pcolor_demo
Pcolor 演示使用pcolor()生成图像。 Pcolor允许您生成二维图像样式图。 下面我们将在Matplotlib中展示如何做到这一点。 123import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.colors import LogNorm 一个简单的 pcolor 示例123456789101112Z = np.random.rand(6, 10)fig, (ax0, ax1) = plt.subplots(2, 1)c = ax0.pcolor(Z)ax0.set_title('default: no edges')c = ax1.pcolor(Z, edgecolors='k', linewidths=4)ax1.set_title('thick edges')fig.tight_layout()plt.show() 比较pcolor与类似的功能Demonstrates similarities between pcolor(...














