|
8 | 8 | the faster method of using PolyCollections, were implemented before we |
9 | 9 | had proper paths with moveto/lineto, closepoly etc in mpl. Now that |
10 | 10 | we have them, we can draw collections of regularly shaped objects with |
11 | | -homogeneous properties more efficiently with a PathCollection. This |
12 | | -example makes a histogram -- its more work to set up the vertex arrays |
| 11 | +homogeneous properties more efficiently with a PathCollection. This |
| 12 | +example makes a histogram -- it's more work to set up the vertex arrays |
13 | 13 | at the outset, but it should be much faster for large numbers of |
14 | | -objects |
| 14 | +objects. |
15 | 15 | """ |
16 | 16 |
|
17 | 17 | import numpy as np |
|
53 | 53 | ax.set_ylim(bottom.min(), top.max()) |
54 | 54 |
|
55 | 55 | plt.show() |
| 56 | + |
| 57 | +############################################################################# |
| 58 | +# It should be noted that instead of creating a three-dimensional array and |
| 59 | +# using `~.path.Path.make_compound_path_from_polys`, we could as well create |
| 60 | +# the compound path directly using vertices and codes as shown below |
| 61 | + |
| 62 | +nrects = len(left) |
| 63 | +nverts = nrects*(1+3+1) |
| 64 | +verts = np.zeros((nverts, 2)) |
| 65 | +codes = np.ones(nverts, int) * path.Path.LINETO |
| 66 | +codes[0::5] = path.Path.MOVETO |
| 67 | +codes[4::5] = path.Path.CLOSEPOLY |
| 68 | +verts[0::5,0] = left |
| 69 | +verts[0::5,1] = bottom |
| 70 | +verts[1::5,0] = left |
| 71 | +verts[1::5,1] = top |
| 72 | +verts[2::5,0] = right |
| 73 | +verts[2::5,1] = top |
| 74 | +verts[3::5,0] = right |
| 75 | +verts[3::5,1] = bottom |
| 76 | + |
| 77 | +barpath = path.Path(verts, codes) |
| 78 | + |
| 79 | +############################################################################# |
| 80 | +# |
| 81 | +# ------------ |
| 82 | +# |
| 83 | +# References |
| 84 | +# """""""""" |
| 85 | +# |
| 86 | +# The use of the following functions, methods, classes and modules is shown |
| 87 | +# in this example: |
| 88 | + |
| 89 | +import matplotlib |
| 90 | +matplotlib.patches |
| 91 | +matplotlib.patches.PathPatch |
| 92 | +matplotlib.path |
| 93 | +matplotlib.path.Path |
| 94 | +matplotlib.path.Path.make_compound_path_from_polys |
| 95 | +matplotlib.axes.Axes.add_patch |
| 96 | +matplotlib.collections.PathCollection |
| 97 | + |
| 98 | +# This example shows an alternative to |
| 99 | +matplotlib.collections.PolyCollection |
| 100 | +matplotlib.axes.Axes.hist |
0 commit comments