[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Add position options for legend?
From: |
Peter Gustafson |
Subject: |
Re: Add position options for legend? |
Date: |
Mon, 13 Aug 2007 09:25:44 -0400 |
User-agent: |
Thunderbird 2.0.0.6 (X11/20070806) |
John W. Eaton wrote:
> Matlab compatibility for this function is more important to me than
> backward compatibility with previous versions of Octave or Octave
> Forge versions of legend, so I would prefer to have a version that
> accepts property lists and handles the "location" property in a
> (currently) compatible way (i.e., "north", "south", ...).
>
> jwe
OK, here is another patch. This should be matlab compatible and retain
backward compatibility with octave-forge (with the exception of -1).
Change it as you see fit.
Pete
2007-08-10 Peter A. Gustafson <address@hidden>
* plot/__go_draw_axes__.m: Add matlab compatible key locations
* plot/legend.m: Changes required for above
Index: scripts/plot/__go_draw_axes__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__go_draw_axes__.m,v
retrieving revision 1.33
diff -c -r1.33 __go_draw_axes__.m
*** scripts/plot/__go_draw_axes__.m 10 Aug 2007 18:41:33 -0000 1.33
--- scripts/plot/__go_draw_axes__.m 13 Aug 2007 13:23:38 -0000
***************
*** 689,698 ****
box = "nobox";
endif
inout = "inside";
! switch (axis_obj.keypos)
! case -1
pos = "right bottom";
inout = "outside";
case 1
pos = "right top";
case 2
--- 689,711 ----
box = "nobox";
endif
inout = "inside";
! keypos = axis_obj.keypos;
! if (ischar (keypos))
! keyout = findstr (keypos, "outside");
! if !(isempty (keyout))
! inout = "outside";
! keypos = keypos (1:keyout-1);
! endif
! endif
! switch (keypos)
! case -3
! pos = "below";
! case -2
pos = "right bottom";
inout = "outside";
+ case -1
+ pos = "right top";
+ inout = "outside";
case 1
pos = "right top";
case 2
***************
*** 701,706 ****
--- 714,740 ----
pos = "left bottom";
case 4
pos = "right bottom";
+ case "north"
+ pos = "center top";
+ case "south"
+ pos = "center bottom";
+ case "east"
+ pos = "right center";
+ case "west"
+ pos = "left center";
+ case "northeast"
+ pos = "right top";
+ case "northwest"
+ pos = "left top";
+ case "southeast"
+ pos = "right bottom";
+ case "southwest"
+ pos = "left bottom";
+ case "best"
+ pos = "";
+ warning ("legend: 'Best' not yet implemented for location
specifier.\n");
+ ## least conflict with data in plot
+ ## least unused space outside plot
otherwise
pos = "";
endswitch
Index: scripts/plot/legend.m
===================================================================
RCS file: /cvs/octave/scripts/plot/legend.m,v
retrieving revision 1.10
diff -c -r1.10 legend.m
*** scripts/plot/legend.m 16 Jun 2007 15:51:49 -0000 1.10
--- scripts/plot/legend.m 13 Aug 2007 13:23:38 -0000
***************
*** 20,30 ****
## -*- texinfo -*-
## @deftypefn {Function File} {} legend (@var{st1}, @var{st2}, @dots{})
! ## @deftypefnx {Function File} {} legend (@var{st1}, @var{st2}, @dots{},
@var{pos})
## @deftypefnx {Function File} {} legend (@var{matstr})
! ## @deftypefnx {Function File} {} legend (@var{matstr}, @var{pos})
## @deftypefnx {Function File} {} legend (@var{cell})
! ## @deftypefnx {Function File} {} legend (@var{cell}, @var{pos})
## @deftypefnx {Function File} {} legend ('@var{func}')
##
## Legend puts a legend on the current plot using the specified strings
--- 20,30 ----
## -*- texinfo -*-
## @deftypefn {Function File} {} legend (@var{st1}, @var{st2}, @dots{})
! ## @deftypefnx {Function File} {} legend (@var{st1}, @var{st2}, @dots{},
"location", @var{pos})
## @deftypefnx {Function File} {} legend (@var{matstr})
! ## @deftypefnx {Function File} {} legend (@var{matstr}, "location", @var{pos})
## @deftypefnx {Function File} {} legend (@var{cell})
! ## @deftypefnx {Function File} {} legend (@var{cell}, "location", @var{pos})
## @deftypefnx {Function File} {} legend ('@var{func}')
##
## Legend puts a legend on the current plot using the specified strings
***************
*** 33,53 ****
## specify legends. Legend works on line graphs, bar graphs, etc.
## Be sure to call plot before calling legend.
##
! ## @var{pos} optionally places the legend in the specified location:
##
! ## @multitable @columnfractions 0.1 0.1 0.8
! ## @item @tab -1 @tab
! ## To the top right of the plot
! ## @item @tab 0 @tab
! ## Don't move the legend box (default)
! ## @item @tab 1 @tab
! ## Upper right-hand corner
! ## @item @tab 2 @tab
! ## Upper left-hand corner
! ## @item @tab 3 @tab
! ## Lower left-hand corner
! ## @item @tab 4 @tab
! ## Lower right-hand corner
## @end multitable
##
## Some specific functions are directely avaliable using @var{func}:
--- 33,59 ----
## specify legends. Legend works on line graphs, bar graphs, etc.
## Be sure to call plot before calling legend.
##
! ## @var{pos} optionally places the legend in the specified location:
##
! ## @multitable @columnfractions 0.06 0.14 0.80
! ## @item @tab north @tab
! ## center top
! ## @item @tab south @tab
! ## center bottom
! ## @item @tab east @tab
! ## right center
! ## @item @tab west @tab
! ## left center
! ## @item @tab northeast @tab
! ## right top (default)
! ## @item @tab northwest @tab
! ## left top
! ## @item @tab southeast @tab
! ## right bottom
! ## @item @tab southwest @tab
! ## left bottom
! ## @item @tab outside @tab
! ## can be appended to any location string
## @end multitable
##
## Some specific functions are directely avaliable using @var{func}:
***************
*** 80,86 ****
if (nargs > 0)
pos = varargin{nargs};
if (isnumeric (pos) && isscalar (pos) && round (pos) == pos)
! if (pos >= -1 && pos <= 4)
set (ca, "keypos", pos);
nargs--;
else
--- 86,92 ----
if (nargs > 0)
pos = varargin{nargs};
if (isnumeric (pos) && isscalar (pos) && round (pos) == pos)
! if (pos >= -3 && pos <= 4)
set (ca, "keypos", pos);
nargs--;
else
***************
*** 88,93 ****
--- 94,108 ----
endif
endif
endif
+
+ if (nargs > 1)
+ pos = varargin{nargs-1};
+ str = lower (varargin{nargs});
+ if (strcmpi (pos, "location") && ischar(str))
+ set (ca, "keypos", str);
+ nargs = nargs - 2;
+ endif
+ endif
kids = get (ca, "children");
nkids = numel (kids);
***************
*** 182,188 ****
%! close all;
%! plot(1:10, 1:10);
%! title("a very long label can sometimes cause problems");
! %! legend({"hello world"}, -1)
%!demo
%! close all;
--- 197,203 ----
%! close all;
%! plot(1:10, 1:10);
%! title("a very long label can sometimes cause problems");
! %! legend({"hello world"}, "location", "northeastoutside")
%!demo
%! close all;
***************
*** 193,197 ****
%! endfor; hold off;
%! title("Signals with random offset and uniform noise")
%! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]");
! %! legend(labels, -1)
%! legend("boxon")
--- 208,212 ----
%! endfor; hold off;
%! title("Signals with random offset and uniform noise")
%! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]");
! %! legend(labels, "location", "northeastoutside")
%! legend("boxon")