donut
绘制甜甜圈Draw donuts (miam!) using Paths and PathPatches. This example shows the effect of the path’s orientations in a compound path. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import numpy as npimport matplotlib.path as mpathimport matplotlib.patches as mpatchesimport matplotlib.pyplot as pltdef wise(v): if v == 1: return "CCW" else: return "CW"def make_circle(r): t = np.arange(0, np.pi * 2.0, 0.0...
ellipse_demo
椭圆演示绘制多个椭圆。此处绘制单个椭圆。将其与Ellipse集合示例进行比较。 12345678910111213141516171819202122import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.patches import EllipseNUM = 250ells = [Ellipse(xy=np.random.rand(2) * 10, width=np.random.rand(), height=np.random.rand(), angle=np.random.rand() * 360) for i in range(NUM)]fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})for e in ells: ax.add_artist(e) e.set_clip_box(ax.bbox) ...
fancybox_demo
Fancybox演示使用Matplotlib绘制精美的盒子。 以下示例显示如何绘制具有不同视觉属性的框。 1234import matplotlib.pyplot as pltimport matplotlib.transforms as mtransformsimport matplotlib.patches as mpatchfrom matplotlib.patches import FancyBboxPatch 首先,我们将展示一些带有fancybox的样本盒。 123456789101112131415styles = mpatch.BoxStyle.get_styles()spacing = 1.2figheight = (spacing * len(styles) + .5)fig1 = plt.figure(1, (4 / 1.5, figheight / 1.5))fontsize = 0.3 * 72for i, stylename in enumerate(sorted(styles)): fig1.text(0.5, (spacing * (len...
line_collection
线段集合使用Matplotlib绘制线条。 LineCollection 允许在图上绘制多条线。 下面我们展示它的一些属性。 12345678910111213141516171819202122232425262728293031323334353637383940import matplotlib.pyplot as pltfrom matplotlib.collections import LineCollectionfrom matplotlib import colors as mcolorsimport numpy as np# In order to efficiently plot many lines in a single set of axes,# Matplotlib has the ability to add the lines all at once. Here is a# simple example showing how it is done.x = np.arange(100)# Here are many sets of y to plot...
hatch_demo
Hatch演示目前仅在PS,PDF,SVG和Agg后端支持阴影线(图案填充多边形)。 123456789101112131415161718192021222324252627import matplotlib.pyplot as pltfrom matplotlib.patches import Ellipse, Polygonfig, (ax1, ax2, ax3) = plt.subplots(3)ax1.bar(range(1, 5), range(1, 5), color='red', edgecolor='black', hatch="/")ax1.bar(range(1, 5), [6] * 4, bottom=range(1, 5), color='blue', edgecolor='black', hatch='//')ax1.set_xticks([1.5, 2.5, 3.5, 4.5])bars = ax2.bar(range...
path_patch
PathPatch对象此示例显示如何通过Matplotlib的API创建 Path 和 PathPatch 对象。 12345678910111213141516171819202122232425262728293031import matplotlib.path as mpathimport matplotlib.patches as mpatchesimport matplotlib.pyplot as pltfig, ax = plt.subplots()Path = mpath.Pathpath_data = [ (Path.MOVETO, (1.58, -2.57)), (Path.CURVE4, (0.35, -1.1)), (Path.CURVE4, (-1.75, 2.0)), (Path.CURVE4, (0.375, 2.0)), (Path.LINETO, (0.85, 1.15)), (Path.CURVE4, (2.2, 3.2)), (Path.CURVE4, (3, 0.05)), (Path.CUR...
patch_collection
圆,楔和多边形此示例演示如何使用修补程序集合。 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import numpy as npfrom matplotlib.patches import Circle, Wedge, Polygonfrom matplotlib.collections import PatchCollectionimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)fig, ax = plt.subplots()resolution = 50 # the number of verticesN = 3x = np.random.rand(N)y = np.random.rand(N)radii = 0.1*np.random.rand(N)patches = []for x1, y1, r ...
marker_path
标记路径使用路径(path)作为绘图的标记(plot)。 12345678910111213141516import matplotlib.pyplot as pltimport matplotlib.path as mpathimport numpy as npstar = mpath.Path.unit_regular_star(6)circle = mpath.Path.unit_circle()# concatenate the circle with an internal cutout of the starverts = np.concatenate([circle.vertices, star.vertices[::-1, ...]])codes = np.concatenate([circle.codes, star.codes])cut_star = mpath.Path(verts, codes)plt.plot(np.arange(10)**2, '--r', marker=cut_star, markersize=15)plt.sho...
quad_bezier
Bezier曲线此示例展示 PathPatch 对象以创建Bezier多曲线路径修补程序。 1234567891011121314151617import matplotlib.path as mpathimport matplotlib.patches as mpatchesimport matplotlib.pyplot as pltPath = mpath.Pathfig, ax = plt.subplots()pp1 = mpatches.PathPatch( Path([(0, 0), (1, 0), (1, 1), (0, 0)], [Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]), fc="none", transform=ax.transData)ax.add_patch(pp1)ax.plot([0.75], [0.25], "ro")ax.set_title('The red point should be on the...
scatter
散点图此示例展示了一个简单的散点图。 123456789101112131415import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed(19680801)N = 50x = np.random.rand(N)y = np.random.rand(N)colors = np.random.rand(N)area = (30 * np.random.rand(N))**2 # 0 to 15 point radiiplt.scatter(x, y, s=area, c=colors, alpha=0.5)plt.show() 参考此示例中显示了以下函数和方法的用法: 1234import matplotlibmatplotlib.axes.Axes.scattermatplotlib.pyplot.scatter 下载这个示例 下载python源码: scatter.py 下载Jupyter notebook: scatte...














