Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 268420b

Browse filesBrowse files
authored
Merge pull request #5391 from dopplershift/tweak-barbs
[MRG+1] Custom pivot for barbs
2 parents 418460b + 01d45a9 commit 268420b
Copy full SHA for 268420b

File tree

Expand file treeCollapse file tree

3 files changed

+24
-6
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-6
lines changed

‎lib/matplotlib/quiver.py

Copy file name to clipboardExpand all lines: lib/matplotlib/quiver.py
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,13 @@ def _h_arrows(self, length):
783783
*length*:
784784
Length of the barb in points; the other parts of the barb
785785
are scaled against this.
786-
Default is 9
786+
Default is 7.
787787
788-
*pivot*: [ 'tip' | 'middle' ]
788+
*pivot*: [ 'tip' | 'middle' | float ]
789789
The part of the arrow that is at the grid point; the arrow rotates
790-
about this point, hence the name *pivot*. Default is 'tip'
790+
about this point, hence the name *pivot*. Default is 'tip'. Can
791+
also be a number, which shifts the start of the barb that many
792+
points from the origin.
791793
792794
*barbcolor*: [ color | color sequence ]
793795
Specifies the color all parts of the barb except any flags. This
@@ -1009,7 +1011,8 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
10091011
10101012
*pivot* specifies the point on the barb around which the
10111013
entire barb should be rotated. Right now, valid options are
1012-
'head' and 'middle'.
1014+
'tip' and 'middle'. Can also be a number, which shifts the start
1015+
of the barb that many points from the origin.
10131016
10141017
*sizes* is a dictionary of coefficients specifying the ratio
10151018
of a given feature to the length of the barb. These features
@@ -1032,7 +1035,7 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
10321035
10331036
*flip* is a flag indicating whether the features should be flipped to
10341037
the other side of the barb (useful for winds in the southern
1035-
hemisphere.
1038+
hemisphere).
10361039
10371040
This function returns list of arrays of vertices, defining a polygon
10381041
for each of the wind barbs. These polygons have been rotated to
@@ -1054,7 +1057,10 @@ def _make_barbs(self, u, v, nflags, nbarbs, half_barb, empty_flag, length,
10541057
full_height = -full_height
10551058

10561059
endx = 0.0
1057-
endy = pivot_points[pivot.lower()]
1060+
try:
1061+
endy = float(pivot)
1062+
except ValueError:
1063+
endy = pivot_points[pivot.lower()]
10581064

10591065
# Get the appropriate angle for the vector components. The offset is
10601066
# due to the way the barb is initially drawn, going down the y-axis.
Loading

‎lib/matplotlib/tests/test_quiver.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_quiver.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ def test_barbs():
142142
cmap='viridis')
143143

144144

145+
@image_comparison(baseline_images=['barbs_pivot_test_image'],
146+
extensions=['png'], remove_text=True)
147+
def test_barbs_pivot():
148+
x = np.linspace(-5, 5, 5)
149+
X, Y = np.meshgrid(x, x)
150+
U, V = 12*X, 12*Y
151+
fig, ax = plt.subplots()
152+
ax.barbs(X, Y, U, V, fill_empty=True, rounding=False, pivot=1.7,
153+
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))
154+
ax.scatter(X, Y, s=49, c='black')
155+
156+
145157
def test_bad_masked_sizes():
146158
'Test error handling when given differing sized masked arrays'
147159
x = np.arange(3)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.