python画心
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 21 21:15:56 2020
@author: 苏麻离青
"""
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
Path = mpath.Path
path_data = [
(Path.MOVETO, (0, -2.8)),
(Path.CURVE4, (-2.8, -1.5)),
(Path.CURVE4, (-3.8, 2.1)),
(Path.CURVE4, (-1.2, 2.3)),#第一次结束
(Path.CURVE4, (-0.4, 2.3)),
(Path.CURVE4, (-0.2, 1.7)),
(Path.CURVE4, (0, 1)),#第二次结束
(Path.CURVE4, (0.2, 1.7)),
(Path.CURVE4, (0.4, 2.3)),
(Path.CURVE4, (1.2, 2.3)),#第三次结束
(Path.CURVE4, (3.8, 2.1)),
(Path.CURVE4, (2.8, -1.5)),
(Path.CURVE4, (0, -2.8)),#第四次结束
(Path.CLOSEPOLY, (0, -4)),
]
codes, verts = zip(*path_data)
path = mpath.Path(verts, codes)
patch = mpatches.PathPatch(path, facecolor='r', alpha=0.5)
ax.add_patch(patch)
x, y = zip(*path.vertices)
line, = ax.plot(x, y, 'go')
ax.grid()
ax.axis('equal')
plt.show()
结果图