|
1 | 1 | from __future__ import absolute_import, division, print_function
|
2 | 2 |
|
| 3 | +import pytest |
3 | 4 | from matplotlib.testing.decorators import image_comparison
|
4 | 5 | import matplotlib.pyplot as plt
|
5 | 6 | import matplotlib.patches as mpatches
|
6 | 7 | import matplotlib.lines as mlines
|
7 |
| -from matplotlib.offsetbox import AnchoredOffsetbox, DrawingArea |
| 8 | +from matplotlib.offsetbox import ( |
| 9 | + AnchoredOffsetbox, DrawingArea, _get_packed_offsets) |
8 | 10 |
|
9 | 11 |
|
10 | 12 | @image_comparison(baseline_images=['offsetbox_clipping'], remove_text=True)
|
@@ -101,16 +103,26 @@ def test_offsetbox_loc_codes():
|
101 | 103 |
|
102 | 104 |
|
103 | 105 | def test_expand_with_tight_layout():
|
104 |
| - fig = plt.figure() |
105 |
| - axes = fig.add_subplot(111) |
106 |
| - |
107 |
| - d1 = [29388871, 12448, 40, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
108 |
| - 0, 0, 0] |
109 |
| - d2 = [28396236, 981940, 22171, 537, 123, 88, 41, 42, 40, 26, 26, |
110 |
| - 84, 6, 2, 0, 0, 0, 0, 0] |
111 |
| - axes.plot(d1, label='series 1') |
112 |
| - axes.plot(d2, label='series 2') |
113 |
| - axes.legend(mode='expand') |
114 |
| - |
115 |
| - # ### THIS IS WHERE THE CRASH HAPPENS |
116 |
| - plt.tight_layout(rect=[0, 0.08, 1, 0.92]) |
| 106 | + # Check issue reported in #10476, and updated due to #10784 |
| 107 | + fig, ax = plt.subplots() |
| 108 | + |
| 109 | + d1 = [1, 2] |
| 110 | + d2 = [2, 1] |
| 111 | + ax.plot(d1, label='series 1') |
| 112 | + ax.plot(d2, label='series 2') |
| 113 | + ax.legend(ncol=2, mode='expand') |
| 114 | + |
| 115 | + fig.tight_layout() # where the crash used to happen |
| 116 | + |
| 117 | + |
| 118 | +@pytest.mark.parametrize('wd_list', |
| 119 | + ([(150, 1)], [(150, 1)]*3, [(0.1, 1)], [(0.1, 1)]*2)) |
| 120 | +@pytest.mark.parametrize('total', (250, 100, 0, -1, None)) |
| 121 | +@pytest.mark.parametrize('sep', (250, 1, 0, -1)) |
| 122 | +@pytest.mark.parametrize('mode', ("expand", "fixed", "equal")) |
| 123 | +def test_get_packed_offsets(wd_list, total, sep, mode): |
| 124 | + # Check a (rather arbitrary) set of parameters due to successive similar |
| 125 | + # issue tickets (at least #10476 and #10784) related to corner cases |
| 126 | + # triggered inside this function when calling higher-level functions |
| 127 | + # (e.g. `Axes.legend`). |
| 128 | + _get_packed_offsets(wd_list, total, sep, mode=mode) |
0 commit comments