|
1 | | -import numpy as np |
| 1 | +""" |
| 2 | +Demo of a PathPatch object. |
| 3 | +""" |
2 | 4 | import matplotlib.path as mpath |
3 | 5 | import matplotlib.patches as mpatches |
4 | 6 | import matplotlib.pyplot as plt |
5 | 7 |
|
6 | | -Path = mpath.Path |
7 | 8 |
|
8 | | -fig = plt.figure() |
9 | | -ax = fig.add_subplot(111) |
| 9 | +fig, ax = plt.subplots() |
10 | 10 |
|
11 | | -pathdata = [ |
| 11 | +Path = mpath.Path |
| 12 | +path_data = [ |
12 | 13 | (Path.MOVETO, (1.58, -2.57)), |
13 | 14 | (Path.CURVE4, (0.35, -1.1)), |
14 | 15 | (Path.CURVE4, (-1.75, 2.0)), |
|
19 | 20 | (Path.CURVE4, (2.0, -0.5)), |
20 | 21 | (Path.CLOSEPOLY, (1.58, -2.57)), |
21 | 22 | ] |
22 | | - |
23 | | -codes, verts = zip(*pathdata) |
| 23 | +codes, verts = zip(*path_data) |
24 | 24 | path = mpath.Path(verts, codes) |
25 | | -patch = mpatches.PathPatch(path, facecolor='red', edgecolor='yellow', alpha=0.5) |
| 25 | +patch = mpatches.PathPatch(path, facecolor='r', alpha=0.5) |
26 | 26 | ax.add_patch(patch) |
27 | 27 |
|
| 28 | +# plot control points and connecting lines |
28 | 29 | x, y = zip(*path.vertices) |
29 | 30 | line, = ax.plot(x, y, 'go-') |
| 31 | + |
30 | 32 | ax.grid() |
31 | | -ax.set_xlim(-3,4) |
32 | | -ax.set_ylim(-3,4) |
33 | | -ax.set_title('spline paths') |
| 33 | +ax.axis('equal') |
34 | 34 | plt.show() |
35 | | - |
36 | | - |
0 commit comments