comparison scripts/plot/legend.m @ 11434:1f54ee6760b5

legend.m: Only one legend per axes (bug 32022)
author Ben Abbott <bpabbott@mac.com>
date Sun, 02 Jan 2011 21:11:24 -0500
parents a140991387fb
children aed2c50c3082
comparison
equal deleted inserted replaced
11433:9f4321024fbf 11434:1f54ee6760b5
464 else 464 else
465 addprops = false; 465 addprops = false;
466 axes (hlegend); 466 axes (hlegend);
467 delete (get (hlegend, "children")); 467 delete (get (hlegend, "children"));
468 endif 468 endif
469
469 ## Add text label to the axis first, checking their extents 470 ## Add text label to the axis first, checking their extents
470 nentries = numel (hplots); 471 nentries = numel (hplots);
471 texthandle = []; 472 texthandle = [];
472 maxwidth = 0; 473 maxwidth = 0;
473 maxheight = 0; 474 maxheight = 0;
772 773
773 function updatelegend (h, d) 774 function updatelegend (h, d)
774 persistent recursive = false; 775 persistent recursive = false;
775 if (! recursive) 776 if (! recursive)
776 recursive = true; 777 recursive = true;
778 hax = getfield (get (h, "userdata"), "handle");
777 [hplots, text_strings] = getlegenddata (h); 779 [hplots, text_strings] = getlegenddata (h);
778 h = legend (fliplr (hplots), get (h, "string")); 780 h = legend (hax, flipud (hplots), get (h, "string"));
779 recursive = false; 781 recursive = false;
780 endif 782 endif
781 endfunction 783 endfunction
782 784
783 function updatelegendtext (h, d) 785 function updatelegendtext (h, d)
985 endfunction 987 endfunction
986 988
987 %!demo 989 %!demo
988 %! clf 990 %! clf
989 %! x = 0:1; 991 %! x = 0:1;
990 %! plot (x, x, ";1;", x, 2*x, x, 3*x, ";3;") 992 %! plot (x, x, ";I am Blue;", x, 2*x, x, 3*x, ";I am Red;")
991 %! title ("1 is Blue, and 3 is Red")
992 993
993 %!demo 994 %!demo
994 %! clf 995 %! clf
995 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); 996 %! plot(1:10, 1:10, 1:10, fliplr(1:10));
996 %! title("incline is blue and decline is green"); 997 %! title("incline is blue and decline is green");
997 %! legend({"I'm blue", "I'm green"}, "location", "east"); 998 %! legend({"I am blue", "I am green"}, "location", "east");
999 %! legend({"I am blue", "I am green"}, "location", "east");
1000 %! legend hide
1001 %! legend show
998 1002
999 %!demo 1003 %!demo
1000 %! clf 1004 %! clf
1001 %! plot(1:10, 1:10, 1:10, fliplr(1:10)); 1005 %! plot(1:10, 1:10, 1:10, fliplr(1:10));
1002 %! title("incline is blue and decline is green"); 1006 %! title("Legend is hidden")
1003 %! legend("I'm blue", "I'm green", "location", "east"); 1007 %! legend({"I am blue", "I am green"}, "location", "east");
1008 %! legend hide
1009
1010 %!demo
1011 %! clf
1012 %! plot(1:10, 1:10, 1:10, fliplr(1:10));
1013 %! title("Legend with box on")
1014 %! legend({"I am blue", "I am green"}, "location", "east");
1015 %! legend boxon
1016
1017 %!demo
1018 %! clf
1019 %! plot(1:10, 1:10, 1:10, fliplr(1:10));
1020 %! title("Legend with text to the right")
1021 %! legend({"I am blue", "I am green"}, "location", "east");
1022 %! legend right
1004 1023
1005 %!demo 1024 %!demo
1006 %! clf 1025 %! clf
1007 %! plot(1:10, 1:10); 1026 %! plot(1:10, 1:10);
1008 %! title("a very long label can sometimes cause problems"); 1027 %! title("a very long label can sometimes cause problems");