8000 Merge pull request #8344 from dstansby/arrow-test · matplotlib/matplotlib@46247c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46247c7

Browse files
committed
Merge pull request #8344 from dstansby/arrow-test
FIX/TST: Add simple ax.arrow test Conflicts: lib/matplotlib/tests/test_axes.py - only keep the test added in PR
1 parent 76a8dc5 commit 46247c7

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/matplotlib/patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
12481248
# The half-arrows contain the midpoint of the stem,
12491249
# which we can omit from the full arrow. Including it
12501250
# twice caused a problem with xpdf.
1251-
coords = np.concatenate([left_half_arrow[:-2],
1251+
coords = np.concatenate([left_half_arrow[:-1],
12521252
right_half_arrow[-2::-1]])
12531253
else:
12541254
raise ValueError("Got unknown shape: %s" % shape)
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import six
55
from six.moves import xrange
6-
from itertools import chain
6+
from itertools import chain, product
77
from distutils.version import LooseVersion
88
import io
99

@@ -230,6 +230,34 @@ def test_basic_annotate():
230230
xytext=(3, 3), textcoords='offset points')
231231

232232

233+
@image_comparison(baseline_images=['arrow_simple'],
234+
extensions=['png'], remove_text=True)
235+
def test_arrow_simple():
236+
# Simple image test for ax.arrow
237+
# kwargs that take discrete values
238+
length_includes_head = (True, False)
239+
shape = ('full', 'left', 'right')
240+
head_starts_at_zero = (True, False)
241+
# Create outer product of values
242+
kwargs = list(product(length_includes_head, shape, head_starts_at_zero))
243+
244+
fig, axs = plt.subplots(3, 4)
245+
for i, (ax, kwarg) in enumerate(zip(axs.flatten(), kwargs)):
246+
ax.set_xlim(-2, 2)
247+
ax.set_ylim(-2, 2)
248+
# Unpack kwargs
249+
(length_includes_head, shape, head_starts_at_zero) = kwarg
250+
theta = 2 * np.pi * i / 12
251+
# Draw arrow
252+
ax.arrow(0, 0, np.sin(theta), np.cos(theta),
253+
width=theta/100,
254+
length_includes_head=length_includes_head,
255+
shape=shape,
256+
head_starts_at_zero=head_starts_at_zero,
257+
head_width=theta / 10,
258+
head_length=theta / 10)
259+
260+
233261
@image_comparison(baseline_images=['polar_axes'])
234262
def test_polar_annotations():
235263
# you can specify the xypoint and the xytext in different

0 commit comments

Comments
 (0)
0