# matplotlib基础4：常见图形绘制（matplotlib.patches模块对象）


# -*- coding: utf-8 -*-
'''

'''
import matplotlib.pyplot as plt
import matplotlib.patches as mp

plt.figure()

'''

Return the left and bottom coords(坐标) of the rectangle
--> return: Rectangle(xy=(0.4, 0.7), width=0.4, height=0.15, angle=0)
'''
rect = mp.Rectangle((0.4, 0.7), 0.4, 0.15, color='r', alpha=0.5, angle=-30)

'''

'''
circ = plt.Circle((0.7, 0.4), 0.2, color='g', alpha=0.5)

'''

--> return: Ellipse(xy=(0.2, 0.8), width=0.2, height=0.3, angle=20)
'''
elli = mp.Ellipse((0.2, 0.8), 0.2, 0.3, angle=20, color='orange', fill=True)

'''

--> return: Poly((0.15, 0.15) ...)

'''
pgon = plt.Polygon(([0.15,0.15], [0.35, 0.4], [0.2, 0.6], [0.3, 0.2]))

# 添加常见的图形对象。这些对象被成为块(patch).完整的patch集合位于matplotlib.patches中

# 添加点的注释
plt.annotate('point-1',
xy=(0.15, 0.15), xycoords='data',
xytext=(-30, -30), textcoords='offset points',
arrowprops=dict(arrowstyle='->',
)
plt.annotate('point-2',
xy=(0.35, 0.4), xycoords='data',
xytext=(-30, -30), textcoords='offset points',
arrowprops=dict(arrowstyle='->',
)
plt.annotate('point-3',
xy=(0.2, 0.6), xycoords='data',
xytext=(-30, -30), textcoords='offset points',
arrowprops=dict(arrowstyle='->',
)
plt.annotate('point-4',
xy=(0.3, 0.2), xycoords='data',
xytext=(-30, -30), textcoords='offset points',
arrowprops=dict(arrowstyle='->',
)

plt.show()
plt.savefig('patches_sample.png', dpi=300, bbox_inches='tight')

'''
dir(matplotlib.patches)
Out[29]:
['Arc',
'Arrow',
'ArrowStyle',
'BoxStyle',
'Circle',             # 圆
'CirclePolygon',
'ConnectionPatch',
'ConnectionStyle',
'Ellipse',            # 椭圆
'FancyArrow',
'FancyArrowPatch',
'FancyBboxPatch',
'Patch',
'Path',
'PathPatch',
'Polygon',            # 多边形
'Rectangle',          # 矩形
'RegularPolygon',
'Wedge',
'YAArrow',
'_Style',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__name__',
'__package__',
'__spec__',
'_patch_alias_map',
'_point_along_a_line',
'_pprint_styles',
'_pprint_table',
'_simpleprint_styles',
'absolute_import',
'allow_rasterization',
'artist',
'bbox_artist',
'cbook',
'colors',
'concatenate_paths',
'division',
'docstring',
'draw_bbox',
'get_cos_sin',
'get_intersection',
'get_parallels',
'inside_circle',
'k',
'make_path_regular',
'make_wedged_bezier2',
'map',
'math',
'mlines',
'mpl',
'np',
'patchdoc',
'print_function',
'six',
'split_bezier_intersecting_with_closedpath',
'split_path_inout',
'transforms',
'unicode_literals',
'warnings',
'zip']
'''