Patches
- 若要繪製幾何圖型,例如矩形或是圓形等,可使用matplotlib.patches函式庫。其中包含了以下數種class(更多細節請參考官方網站):
- matplotlib.patches.Arc(xy, width, height, angle=0.0, theta1=0.0, theta2=360.0, **kwargs)
- matplotlib.patches.Arrow(x, y, dx, dy, width=1.0, **kwargs)
- matplotlib.patches.ArrowStyle[source]
- ArrowStyle.Fancy(head_length=.4, head_width=.4, tail_width=.4)
- ArrowStyle("Fancy", head_length=.4, head_width=.4, tail_width=.4)
- ArrowStyle("Fancy, head_length=.4, head_width=.4, tail_width=.4")
- matplotlib.patches.BoxStyle[source]
- BoxStyle.Round(pad=0.2)
- BoxStyle("Round", pad=0.2)
- BoxStyle("Round, pad=0.2")
- matplotlib.patches.Circle(xy, radius=5, **kwargs)
- matplotlib.patches.CirclePolygon(xy, radius=5, resolution=20, **kwargs)
- matplotlib.patches.ConnectionPatch(xyA, xyB, coordsA, coordsB=None, axesA=None, axesB=None, arrowstyle='-', arrow_transmuter=None, connectionstyle='arc3', connector=None, patchA=None, patchB=None, shrinkA=0.0, shrinkB=0.0, mutation_scale=10.0, mutation_aspect=None, clip_on=False, dpi_cor=1.0, **kwargs)
- matplotlib.patches.ConnectionStyle
- ConnectionStyle.Arc3(rad=0.2)
- ConnectionStyle("Arc3", rad=0.2)
- ConnectionStyle("Arc3, rad=0.2")
- matplotlib.patches.Ellipse(xy, width, height, angle=0.0, **kwargs)
- matplotlib.patches.FancyArrow(x, y, dx, dy, width=0.001, length_includes_head=False, head_width=None, head_length=None, shape='full', overhang=0, head_starts_at_zero=False, **kwargs)
- matplotlib.patches.FancyArrowPatch(posA=None, posB=None, path=None, arrowstyle='simple', arrow_transmuter=None, connectionstyle='arc3', connector=None, patchA=None, patchB=None, shrinkA=2, shrinkB=2, mutation_scale=1, mutation_aspect=None, dpi_cor=1, **kwargs)
- matplotlib.patches.FancyBboxPatch(xy, width, height, boxstyle='round', bbox_transmuter=None, mutation_scale=1.0, mutation_aspect=None, **kwargs)
- matplotlib.patches.Patch(edgecolor=None, facecolor=None, color=None, linewidth=None, linestyle=None, antialiased=None, hatch=None, fill=True, capstyle=None, joinstyle=None, **kwargs)
- matplotlib.patches.PathPatch(path, **kwargs)
- matplotlib.patches.Polygon(xy, closed=True, **kwargs)
- matplotlib.patches.Rectangle(xy, width, height, angle=0.0, **kwargs)
- matplotlib.patches.RegularPolygon(xy, numVertices, radius=5, orientation=0, **kwargs)
- matplotlib.patches.Shadow(patch, ox, oy, props=None, **kwargs)
- matplotlib.patches.Wedge(center, r, theta1, theta2, width=None, **kwargs)
- matplotlib.patches.YAArrow(figure, xytip, xybase, width=4, frac=0.1, headwidth=12, **kwargs)
Ellipse
- 以Ellipse為例。
- 橢圓的參數為xy(中心點)、width、height、angle(旋轉角度),請見下面的例子:
- createEll(): 用來建立一個ellipse的物件。
- fig, ax = plt.subplots(subplot_kw={'aspect':'equal'}): 將圖型分為圖案(fig)與軸(ax>兩個物件。
- ax.add_artist(i): 將ellipse(i)加入圖型中。
- i.set_alpha(np.random.rand()): 設定transparency。
- i.set_facecolor(np.random.rand(3)): 設定顏色。
- ax.set_xlim(0,10): 設定x軸的範圍。
pyplot11.py