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

Skip to content

Commit 9ee6ff5

Browse files
authored
Merge pull request #20458 from dstansby/leg-text
Set the axes of legend text
2 parents 76522fa + 4e8e786 commit 9ee6ff5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/matplotlib/legend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
828828
children=[self._legend_title_box,
829829
self._legend_handle_box])
830830
self._legend_box.set_figure(self.figure)
831+
self._legend_box.axes = self.axes
831832
self.texts = text_list
832833
self.legendHandles = handle_list
833834

lib/matplotlib/tests/test_legend.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,12 @@ def test_legend_face_edgecolor():
852852
ax.fill_between([0, 1, 2], [1, 2, 3], [2, 3, 4],
853853
facecolor='r', edgecolor='face', label='Fill')
854854
ax.legend()
855+
856+
857+
def test_legend_text_axes():
858+
fig, ax = plt.subplots()
859+
ax.plot([1, 2], [3, 4], label='line')
860+
leg = ax.legend()
861+
862+
assert leg.axes is ax
863+
assert leg.get_texts()[0].axes is ax

0 commit comments

Comments
 (0)