# HG changeset patch # User Rik # Date 1590443850 25200 # Node ID d4b71e99c2be44b98a79b17ac88b9c3d83013ba1 # Parent 2969b94cac9fd7deacb7c16a4e499c1c0dab24ce# Parent 938b234f395a7926f4461c260d095e3c8dbfe18d maint: merge stable to default. diff -r 2969b94cac9f -r d4b71e99c2be scripts/plot/appearance/legend.m --- a/scripts/plot/appearance/legend.m Mon May 25 22:28:38 2020 +0200 +++ b/scripts/plot/appearance/legend.m Mon May 25 14:57:30 2020 -0700 @@ -33,6 +33,7 @@ ## @deftypefnx {} {} legend (@var{hobjs}, @dots{}) ## @deftypefnx {} {} legend ("@var{command}") ## @deftypefnx {} {} legend (@var{hax}, @dots{}) +## @deftypefnx {} {} legend (@var{hleg}, @dots{}) ## @deftypefnx {} {@var{hleg, hplt} =} legend (@dots{}) ## ## Display a legend for the current axes using the specified strings as labels. @@ -46,6 +47,9 @@ ## If the first argument @var{hax} is an axes handle, then add a legend to this ## axes, rather than the current axes returned by @code{gca}. ## +## If the first argument @var{hleg} is a legend handle, then operate on this +## legend rather than the legend of the current axes. +## ## Legend labels are associated with the axes' children; The first label is ## assigned to the first object that was plotted in the axes, the second label ## to the next object plotted, etc. To label specific data objects, without @@ -576,12 +580,21 @@ nargs = numel (varargin); ## Find peer axes - if (nargs > 0 - && (! ishghandle (varargin{1}) - || (strcmp (get (varargin{1}, "type"), "axes") - && ! strcmp (get (varargin{1}, "tag"), "legend")))) - [axes_handles, varargin, nargs] = __plt_get_axis_arg__ ("legend", - varargin{:}); + if (nargs > 0) + if (! ishghandle (varargin{1})) + [axes_handles, varargin, nargs] = __plt_get_axis_arg__ ("legend", + varargin{:}); + elseif (strcmp (get (varargin{1}, "type"), "axes")) + if (strcmp (get (varargin{1}, "tag"), "legend")) + legend_handle = varargin{1}; + varargin(1) = []; + nargs--; + axes_handles = getappdata (legend_handle, "__axes_handle__"); + else + [axes_handles, varargin, nargs] = __plt_get_axis_arg__ ("legend", + varargin{:}); + endif + endif if (isempty (axes_handles)) axes_handles = gca (); endif @@ -598,13 +611,14 @@ endif ## Find any existing legend object associated with axes - try - legend_handle = get (axes_handles, "__legend_handle__"); - if (iscell (legend_handle)) - legend_handle = unique (cell2mat (legend_handle)); - endif - catch - end_try_catch + if (isempty (legend_handle)) + try + legend_handle = get (axes_handles, "__legend_handle__"); + if (iscell (legend_handle)) + legend_handle = unique (cell2mat (legend_handle)); + endif + end_try_catch + endif ## Legend actions actions = {"show", "hide", "toggle", "boxon", ...