8000 Backport PR #29908: TST: Use text placeholders for empty legends · matplotlib/matplotlib@9637932 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9637932

Browse files
tacaswellrcomer
authored andcommitted
Backport PR #29908: TST: Use text placeholders for empty legends
1 parent 7dfb4e4 commit 9637932

File tree

12 files changed

+921
-390
lines changed

12 files changed

+921
-390
lines changed
Loading
Binary file not shown.
Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight.svg

Lines changed: 900 additions & 369 deletions
Loading
Loading
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4512,14 +4512,12 @@ def test_hist_stacked_weighted():
45124512

45134513

45144514
@image_comparison(['stem.png'], style='mpl20', remove_text=True)
4515-
def test_stem():
4515+
def test_stem(text_placeholders):
45164516
x = np.linspace(0.1, 2 * np.pi, 100)
45174517

45184518
fig, ax = plt.subplots()
4519-
# Label is a single space to force a legend to be drawn, but to avoid any
4520-
# text being drawn
45214519
ax.stem(x, np.cos(x),
4522-
linefmt='C2-.', markerfmt='k+', basefmt='C1-.', label=' ')
4520+
linefmt='C2-.', markerfmt='k+', basefmt='C1-.', label='stem')
45234521
ax.legend()
45244522

45254523

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,16 @@ def test_pdfpages_fspath():
312312
pdf.savefig(plt.figure())
313313

314314

315-
@image_comparison(['hatching_legend.pdf'])
316-
def test_hatching_legend():
315+
@image_comparison(['hatching_legend.pdf'], style='mpl20')
316+
def test_hatching_legend(text_placeholders):
317317
"""Test for correct hatching on patches in legend"""
318318
fig = plt.figure(figsize=(1, 2))
319319

320320
a = Rectangle([0, 0], 0, 0, facecolor="green", hatch="XXXX")
321321
b = Rectangle([0, 0], 0, 0, facecolor="blue", hatch="XXXX")
322322

323+
# Verify that hatches in PDFs work after empty labels. See
324+
# https://github.com/matplotlib/matplotlib/issues/4469
323325
fig.legend([a, b, a, b], ["", "", "", ""])
324326

325327

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
from matplotlib.ticker import FuncFormatter
1111

1212

13-
@image_comparison(['bbox_inches_tight'], remove_text=True,
13+
@image_comparison(['bbox_inches_tight'], remove_text=True, style='mpl20',
1414
savefig_kwarg={'bbox_inches': 'tight'})
15-
def test_bbox_inches_tight():
15+
def test_bbox_inches_tight(text_placeholders):
1616
#: Test that a figure saved using bbox_inches='tight' is clipped correctly
1717
data = [[66386, 174296, 75131, 577908, 32015],
1818
[58230, 381139, 78045, 99308, 160454],
1919
[89135, 80552, 152558, 497981, 603535],
2020
[78415, 81858, 150656, 193263, 69638],
2121
[139361, 331509, 343164, 781380, 52269]]
2222

23-
col_labels = row_labels = [''] * 5
23+
col_labels = ('Freeze', 'Wind', 'Flood', 'Quake', 'Hail')
24+
row_labels = [f'{x} year' for x in (100, 50, 20, 10, 5)]
2425

2526
rows = len(data)
2627
ind = np.arange(len(col_labels)) + 0.3 # the x locations for the groups
@@ -30,13 +31,13 @@ def test_bbox_inches_tight():
3031
# the bottom values for stacked bar chart
3132
fig, ax = plt.subplots(1, 1)
3233
for row in range(rows):
33-
ax.bar(ind, data[row], width, bottom=yoff, align='edge', color='b')
34+
ax.bar(ind, data[row], width, bottom=yoff, align='edge')
3435
yoff = yoff + data[row]
35-
cell_text.append([''])
36+
cell_text.append([f'{x / 1000:1.1f}' for x in yoff])
3637
plt.xticks([])
3738
plt.xlim(0, 5)
38-
plt.legend([''] * 5, loc=(1.2, 0.2))
39-
fig.legend([''] * 5, bbox_to_anchor=(0, 0.2), loc='lower left')
39+
plt.legend(['1', '2', '3', '4', '5'], loc=(1.2, 0.2))
40+
fig.legend(['a', 'b', 'c', 'd', 'e'], bbox_to_anchor=(0, 0.2), loc='lower left')
4041
# Add a table at the bottom of the axes
4142
cell_text.reverse()
4243
plt.table(cellText=cell_text, rowLabels=row_labels, colLabels=col_labels,

0 commit comments

Comments
 (0)
0