Skip to content

Commit 242ae7d

Browse files
committed
DOC: Simplify Line, Poly and RegularPoly example
- use `color` kwarg instead of separate `add_color()` - remove `autolim=True` from `add_collection()` calls as that is the default anyway
1 parent dfc888c commit 242ae7d

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

galleries/examples/shapes_and_collections/collections.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,53 +47,36 @@
4747

4848

4949
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
5152
trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)
5253
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)
6855
ax1.set_title('LineCollection using offsets')
6956

7057

7158
# The same data as above, but fill the curves.
7259
col = collections.PolyCollection(
73-
[spiral], offsets=xyo, offset_transform=ax2.transData)
60+
[spiral], offsets=xyo, offset_transform=ax2.transData, color=colors)
7461
trans = transforms.Affine2D().scale(fig.dpi/72.0)
7562
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)
8064
ax2.set_title('PolyCollection using offsets')
8165

82-
# 7-sided regular polygons
8366

67+
# 7-sided regular polygons
8468
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)
8671
trans = transforms.Affine2D().scale(fig.dpi / 72.0)
8772
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)
9074
ax3.set_title('RegularPolyCollection using offsets')
9175

9276

9377
# Simulate a series of ocean current profiles, successively
9478
# offset by 0.1 m/s so that they form what is sometimes called
9579
# a "waterfall" plot or a "stagger" plot.
96-
9780
nverts = 60
9881
ncurves = 20
9982
offs = (0.1, 0.0)
@@ -107,15 +90,12 @@
10790
curve = np.column_stack([xxx, yy * 100])
10891
segs.append(curve)
10992

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)
11395
ax4.set_title('Successive data offsets')
11496
ax4.set_xlabel('Zonal velocity component (m/s)')
11597
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
11999

120100
plt.show()
121101

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy