Skip to content

Commit fb4f7eb

Browse files
committed
Minor cleanup and add test for offsetbox
1 parent 6c721e9 commit fb4f7eb

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _get_packed_offsets(widths, total, sep, mode="fixed"):
114114
offsets = offsets_[:-1]
115115
return total, offsets
116116

117-
elif mode == "equal":
117+
else: # "equal"
118118
maxh = max(widths)
119119
if total is None:
120120
if sep is None:
@@ -166,13 +166,13 @@ def _get_aligned_offsets(hd_list, height, align="baseline"):
166166
descent = max(d for h, d in hd_list)
167167
height = height_descent + descent
168168
offsets = [0. for h, d in hd_list]
169-
elif align in ["left", "top"]:
169+
elif align in ("left", "top"):
170170
descent = 0.
171171
offsets = [d for h, d in hd_list]
172-
elif align in ["right", "bottom"]:
172+
elif align in ("right", "bottom"):
173173
descent = 0.
174174
offsets = [height - h + d for h, d in hd_list]
175-
elif align == "center":
175+
else: # "center"
176176
descent = 0.
177177
offsets = [(height - h) * .5 + d for h, d in hd_list]
178178

lib/matplotlib/tests/test_offsetbox.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from numpy.testing import assert_allclose
66
import pytest
77

8-
from matplotlib.testing.decorators import image_comparison
8+
from matplotlib.testing.decorators import check_figures_equal, image_comparison
99
import matplotlib.pyplot as plt
1010
import matplotlib.patches as mpatches
1111
import matplotlib.lines as mlines
@@ -28,6 +28,7 @@ def test_offsetbox_clipping():
2828
fig, ax = plt.subplots()
2929
size = 100
3030
da = DrawingArea(size, size, clip=True)
31+
assert da.clip_children
3132
bg = mpatches.Rectangle((0, 0), size, size,
3233
facecolor='#CCCCCC',
3334
edgecolor='None',
@@ -335,3 +336,39 @@ def test_arrowprops_copied():
335336
arrowprops=arrowprops)
336337
assert ab.arrowprops is not ab
337338
assert arrowprops["relpos"] == (.3, .7)
339+
340+
341+
def test_annotationbbox_properties():
342+
ab = AnnotationBbox(DrawingArea(20, 20, 0, 0, clip=True), (0.5, 0.5),
343+
xycoords='data')
344+
assert ab.xyann == (0.5, 0.5) # xy if xybox not given
345+
assert ab.anncoords == 'data' # xycoords if boxcoords not given
346+
347+
ab = AnnotationBbox(DrawingArea(20, 20, 0, 0, clip=True), (0.5, 0.5),
348+
xybox=(-0.2, 0.4), xycoords='data',
349+
boxcoords='axes fraction')
350+
assert ab.xyann == (-0.2, 0.4) # xybox if given
351+
assert ab.anncoords == 'axes fraction' # boxcoords if given
352+
353+
354+
def test_textarea_properties():
355+
ta = TextArea('Foo')
356+
assert ta.get_text() == 'Foo'
357+
assert not ta.get_multilinebaseline()
358+
359+
ta.set_text('Bar')
360+
ta.set_multilinebaseline(True)
361+
assert ta.get_text() == 'Bar'
362+
assert ta.get_multilinebaseline()
363+
364+
365+
@check_figures_equal()
366+
def test_textarea_set_text(fig_test, fig_ref):
367+
ax_ref = fig_ref.add_subplot()
368+
text0 = AnchoredText("Foo", "upper left")
369+
ax_ref.add_artist(text0)
370+
371+
ax_test = fig_test.add_subplot()
372+
text1 = AnchoredText("Bar", "upper left")
373+
ax_test.add_artist(text1)
374+
text1.txt.set_text("Foo")

0 commit comments

Comments
 (0)