Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d16c4a1

Browse files
authored
Merge pull request #8344 from dstansby/arrow-test
FIX/TST: Add simple ax.arrow test
2 parents 93c00b5 + a4cfcd8 commit d16c4a1

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
@@ -1252,7 +1252,7 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
12521252
# The half-arrows contain the midpoint of the stem,
12531253
# which we can omit from the full arrow. Including it
12541254
# twice caused a problem with xpdf.
1255-
coords = np.concatenate([left_half_arrow[:-2],
1255+
coords = np.concatenate([left_half_arrow[:-1],
12561256
right_half_arrow[-2::-1]])
12571257
else:
12581258
raise ValueError("Got unknown shape: %s" % shape)

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

@@ -263,6 +263,34 @@ def test_basic_annotate():
263263
xytext=(3, 3), textcoords='offset points')
264264

265265

266+
@image_comparison(baseline_images=['arrow_simple'],
267+
extensions=['png'], remove_text=True)
268+
def test_arrow_simple():
269+
# Simple image test for ax.arrow
270+
# kwargs that take discrete values
271+
length_includes_head = (True, False)
272+
shape = ('full', 'left', 'right')
273+
head_starts_at_zero = (True, False)
274+
# Create outer product of values
275+
kwargs = list(product(length_includes_head, shape, head_starts_at_zero))
276+
277+
fig, axs = plt.subplots(3, 4)
278+
for i, (ax, kwarg) in enumerate(zip(axs.flatten(), kwargs)):
279+
ax.set_xlim(-2, 2)
280+
ax.set_ylim(-2, 2)
281+
# Unpack kwargs
282+
(length_includes_head, shape, head_starts_at_zero) = kwarg
283+
theta = 2 * np.pi * i / 12
284+
# Draw arrow
285+
ax.arrow(0, 0, np.sin(theta), np.cos(theta),
286+
width=theta/100,
287+
length_includes_head=length_includes_head,
288+
shape=shape,
289+
head_starts_at_zero=head_starts_at_zero,
290+
head_width=theta / 10,
291+
head_length=theta / 10)
292+
293+
266294
def test_annotate_default_arrow():
267295
# Check that we can make an annotation arrow with only default properties.
268296
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)