diff --git a/lib/matplotlib/backends/qt_editor/figureoptions.py b/lib/matplotlib/backends/qt_editor/figureoptions.py index cd4e9583cce5..137b28bc2464 100644 --- a/lib/matplotlib/backends/qt_editor/figureoptions.py +++ b/lib/matplotlib/backends/qt_editor/figureoptions.py @@ -61,6 +61,7 @@ def convert_limits(lim, converter): ) for name, axis in axis_map.items() ]), + ('Show legend', axes.legend_ is not None and axes.legend_.get_visible()), ('(Re-)Generate automatic legend', False), ] @@ -196,6 +197,7 @@ def apply_callback(data): title = general.pop(0) axes.title.set_text(title) generate_legend = general.pop() + show_legend = general.pop() for i, (name, axis) in enumerate(axis_map.items()): axis_min = general[4*i] @@ -248,14 +250,32 @@ def apply_callback(data): if generate_legend: draggable = None ncols = 1 + kwargs = {} if axes.legend_ is not None: old_legend = axes.get_legend() draggable = old_legend._draggable is not None ncols = old_legend._ncols - new_legend = axes.legend(ncols=ncols) + kwargs = { + 'loc': old_legend._loc_real, + 'title': old_legend.get_title().get_text(), + 'frameon': old_legend.get_frame_on(), + 'shadow': old_legend.shadow, + } + + # Clone frame properties if the frame exists + frame = old_legend.get_frame() + if frame is not None: + kwargs['edgecolor'] = frame.get_edgecolor() + kwargs['facecolor'] = frame.get_facecolor() + kwargs['framealpha'] = frame.get_alpha() + + new_legend = axes.legend(ncols=ncols, **kwargs) if new_legend: new_legend.set_draggable(draggable) + if axes.legend_ is not None: + axes.legend_.set_visible(show_legend) + # Redraw figure = axes.get_figure() figure.canvas.draw()