|
47 | 47 |
|
48 | 48 |
|
49 | 49 | col = collections.LineCollection(
|
50 |
| - [spiral], offsets=xyo, offset_transform=ax1.transData) |
| 50 | + [spiral], offsets=xyo, offset_transform=ax1.transData, color=colors) |
| 51 | +# transform the line segments such that their size is given in points |
51 | 52 | trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)
|
52 | 53 | col.set_transform(trans) # the points to pixels transform
|
53 |
| -# Note: the first argument to the collection initializer |
54 |
| -# must be a list of sequences of (x, y) tuples; we have only |
55 |
| -# one sequence, but we still have to put it in a list. |
56 |
| -ax1.add_collection(col, autolim=True) |
57 |
| -# autolim=True enables autoscaling. For collections with |
58 |
| -# offsets like this, it is neither efficient nor accurate, |
59 |
| -# but it is good enough to generate a plot that you can use |
60 |
| -# as a starting point. If you know beforehand the range of |
61 |
| -# x and y that you want to show, it is better to set them |
62 |
| -# explicitly, set the *autolim* keyword argument to False. |
63 |
| - |
64 |
| -# Make a transform for the line segments such that their size is |
65 |
| -# given in points: |
66 |
| -col.set_color(colors) |
67 |
| - |
| 54 | +ax1.add_collection(col) |
68 | 55 | ax1.set_title('LineCollection using offsets')
|
69 | 56 |
|
70 | 57 |
|
71 | 58 | # The same data as above, but fill the curves.
|
72 | 59 | col = collections.PolyCollection(
|
73 |
| - [spiral], offsets=xyo, offset_transform=ax2.transData) |
| 60 | + [spiral], offsets=xyo, offset_transform=ax2.transData, color=colors) |
74 | 61 | trans = transforms.Affine2D().scale(fig.dpi/72.0)
|
75 | 62 | col.set_transform(trans) # the points to pixels transform
|
76 |
| -ax2.add_collection(col, autolim=True) |
77 |
| -col.set_color(colors) |
78 |
| - |
79 |
| - |
| 63 | +ax2.add_collection(col) |
80 | 64 | ax2.set_title('PolyCollection using offsets')
|
81 | 65 |
|
82 |
| -# 7-sided regular polygons |
83 | 66 |
|
| 67 | +# 7-sided regular polygons |
84 | 68 | col = collections.RegularPolyCollection(
|
85 |
| - 7, sizes=np.abs(xx) * 10.0, offsets=xyo, offset_transform=ax3.transData) |
| 69 | + 7, sizes=np.abs(xx) * 10.0, offsets=xyo, offset_transform=ax3.transData, |
| 70 | + color=colors) |
86 | 71 | trans = transforms.Affine2D().scale(fig.dpi / 72.0)
|
87 | 72 | col.set_transform(trans) # the points to pixels transform
|
88 |
| -ax3.add_collection(col, autolim=True) |
89 |
| -col.set_color(colors) |
| 73 | +ax3.add_collection(col) |
90 | 74 | ax3.set_title('RegularPolyCollection using offsets')
|
91 | 75 |
|
92 | 76 |
|
93 | 77 | # Simulate a series of ocean current profiles, successively
|
94 | 78 | # offset by 0.1 m/s so that they form what is sometimes called
|
95 | 79 | # a "waterfall" plot or a "stagger" plot.
|
96 |
| - |
97 | 80 | nverts = 60
|
98 | 81 | ncurves = 20
|
99 | 82 | offs = (0.1, 0.0)
|
|
107 | 90 | curve = np.column_stack([xxx, yy * 100])
|
108 | 91 | segs.append(curve)
|
109 | 92 |
|
110 |
| -col = collections.LineCollection(segs, offsets=offs) |
111 |
| -ax4.add_collection(col, autolim=True) |
112 |
| -col.set_color(colors) |
| 93 | +col = collections.LineCollection(segs, offsets=offs, color=colors) |
| 94 | +ax4.add_collection(col) |
113 | 95 | ax4.set_title('Successive data offsets')
|
114 | 96 | ax4.set_xlabel('Zonal velocity component (m/s)')
|
115 | 97 | ax4.set_ylabel('Depth (m)')
|
116 |
| -# Reverse the y-axis so depth increases downward |
117 |
| -ax4.set_ylim(ax4.get_ylim()[::-1]) |
118 |
| - |
| 98 | +ax4.invert_yaxis() # so that depth increases downward |
119 | 99 |
|
120 | 100 | plt.show()
|
121 | 101 |
|
|
0 commit comments