Mercurial > hg > octave-shane
changeset 7194:a927a2871a93
[project @ 2007-11-26 23:06:12 by jwe]
author | jwe |
---|---|
date | Mon, 26 Nov 2007 23:06:13 +0000 |
parents | cbdee3da62bd |
children | 97d2da8ed746 |
files | scripts/ChangeLog scripts/plot/Makefile.in scripts/plot/__go_draw_axes__.m scripts/plot/xlabel.m scripts/plot/ylabel.m scripts/plot/zlabel.m src/ChangeLog src/graphics.cc src/graphics.h.in |
diffstat | 9 files changed, 192 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,13 @@ 2007-11-26 David Bateman <dbateman@free.fr> + * plot/plotyy.m: New function + * plot/Makefile.in (SOURCES): Add it here. + * plot/__go_draw_axes__.m: Force axis margins for plotyy. Set text + color for {x|y|z}label and {x|y|z}tics. Also force the label of + {x|y}label to respect the axis position. + * plot/xlabel.m, plot/ylabel.m, plot/zlabel.m: Accept an axis + handle as the first argument. + * pkg/pkg.m (pkg:install): When loading the installed packages index into installed_pkgs_lst and not descriptions..
--- a/scripts/plot/Makefile.in +++ b/scripts/plot/Makefile.in @@ -112,6 +112,7 @@ pie.m \ plot.m \ plot3.m \ + plotyy.m \ polar.m \ print.m \ quiver.m \
--- a/scripts/plot/__go_draw_axes__.m +++ b/scripts/plot/__go_draw_axes__.m @@ -39,6 +39,10 @@ if (! isempty (axis_obj.position)) pos = axis_obj.position; + fprintf (plot_stream, "set tmargin 3;\n"); + fprintf (plot_stream, "set bmargin 3;\n"); + fprintf (plot_stream, "set lmargin 10;\n"); + fprintf (plot_stream, "set rmargin 10;\n"); endif if (! strcmp (axis_obj.__colorbar__, "none")) @@ -74,49 +78,74 @@ if (! isempty (axis_obj.xlabel)) t = get (axis_obj.xlabel); angle = t.rotation; + colorspec = get_text_colorspec (axis_obj.xcolor); if (isempty (t.string)) - fputs (plot_stream, "unset xlabel;\n"); + fprintf (plot_stream, "unset xlabel;\n"); + fprintf (plot_stream, "unset x2label;\n"); else [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", have_newer_gnuplot); - fprintf (plot_stream, "set xlabel \"%s\" font \"%s,%d\"", - undo_string_escapes (tt), f, s); + if (strcmpi (axis_obj.xaxislocation, "top")) + fprintf (plot_stream, "set x2label \"%s\" %s font \"%s,%d\"", + undo_string_escapes (tt), colorspec, f, s); + else + fprintf (plot_stream, "set xlabel \"%s\" %s font \"%s,%d\"", + undo_string_escapes (tt), colorspec, f, s); + endif if (have_newer_gnuplot) ## Rotation of xlabel not yet support by gnuplot as of 4.2, but ## there is no message about it. fprintf (plot_stream, " rotate by %f", angle); endif fputs (plot_stream, ";\n"); + if (strcmpi (axis_obj.xaxislocation, "top")) + fprintf (plot_stream, "unset xlabel;\n"); + else + fprintf (plot_stream, "unset x2label;\n"); + endif endif endif if (! isempty (axis_obj.ylabel)) t = get (axis_obj.ylabel); angle = t.rotation; + colorspec = get_text_colorspec (axis_obj.ycolor); if (isempty (t.string)) - fputs (plot_stream, "unset ylabel;\n"); + fprintf (plot_stream, "unset ylabel;\n"); + fprintf (plot_stream, "unset y2label;\n"); else [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", have_newer_gnuplot); - fprintf (plot_stream, "set ylabel \"%s\" font \"%s,%d\"", - undo_string_escapes (tt), f, s); + if (strcmpi (axis_obj.yaxislocation, "right")) + fprintf (plot_stream, "set y2label \"%s\" %s font \"%s,%d\"", + undo_string_escapes (tt), colorspec, f, s); + else + fprintf (plot_stream, "set ylabel \"%s\" %s font \"%s,%d\"", + undo_string_escapes (tt), colorspec, f, s); + endif if (have_newer_gnuplot) fprintf (plot_stream, " rotate by %f;\n", angle); endif fputs (plot_stream, ";\n"); + if (strcmpi (axis_obj.yaxislocation, "right")) + fprintf (plot_stream, "unset ylabel;\n"); + else + fprintf (plot_stream, "unset y2label;\n"); + endif endif endif if (! isempty (axis_obj.zlabel)) t = get (axis_obj.zlabel); angle = t.rotation; + colorspec = get_text_colorspec (axis_obj.zcolor); if (isempty (t.string)) fputs (plot_stream, "unset zlabel;\n"); else [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string", have_newer_gnuplot); - fprintf (plot_stream, "set zlabel \"%s\" font \"%s,%d\"", - undo_string_escapes (tt), f, s); + fprintf (plot_stream, "set zlabel \"%s\" %s font \"%s,%d\"", + undo_string_escapes (tt), colorspec, f, s); if (have_newer_gnuplot) ## Rotation of zlabel not yet support by gnuplot as of 4.2, but ## there is no message about it. @@ -971,31 +1000,7 @@ endif if (isnumeric (color)) - if (have_newer_gnuplot) - colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", - round (255*color)); - else - if (isequal (color, [0,0,0])) - typ = -1; - elseif (isequal (color, [1,0,0])) - typ = 1; - elseif (isequal (color, [0,1,0])) - typ = 2; - elseif (isequal (color, [0,0,1])) - typ = 3; - elseif (isequal (color, [1,0,1])) - typ = 4; - elseif (isequal (color, [0,1,1])) - typ = 5; - elseif (isequal (color, [1,1,1])) - typ = -1; - elseif (isequal (color, [1,1,0])) - typ = 7; - else - typ = -1; - endif - colorspec = sprintf ("textcolor lt %d", typ); - endif + colorspec = get_text_colorspec (color); endif if (nd == 3) @@ -1530,31 +1535,32 @@ function do_tics (obj, plot_stream) if (strcmpi (obj.xaxislocation, "top")) do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, - "x2", plot_stream); + obj.xcolor, "x2", plot_stream); do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, - "x", plot_stream); + obj.xcolor, "x", plot_stream); else do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel, - "x", plot_stream); + obj.xcolor, "x", plot_stream); do_tics_1 ("manual", [], obj.xticklabelmode, obj.xticklabel, - "x2", plot_stream); + obj.xcolor, "x2", plot_stream); endif if (strcmpi (obj.yaxislocation, "right")) do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, - "y2", plot_stream); + obj.ycolor, "y2", plot_stream); do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, - "y", plot_stream); + obj.ycolor, "y", plot_stream); else do_tics_1 (obj.ytickmode, obj.ytick, obj.yticklabelmode, obj.yticklabel, - "y", plot_stream); + obj.ycolor, "y", plot_stream); do_tics_1 ("manual", [], obj.yticklabelmode, obj.yticklabel, - "y2", plot_stream); + obj.ycolor, "y2", plot_stream); endif do_tics_1 (obj.ztickmode, obj.ztick, obj.zticklabelmode, obj.zticklabel, - "z", plot_stream); + obj.zcolor, "z", plot_stream); endfunction -function do_tics_1 (ticmode, tics, labelmode, labels, ax, plot_stream) +function do_tics_1 (ticmode, tics, labelmode, labels, color, ax, plot_stream) + colorspec = get_text_colorspec (color); if (strcmpi (ticmode, "manual")) if (isempty (tics)) fprintf (plot_stream, "unset %stics;\n", ax); @@ -1567,7 +1573,7 @@ ntics = numel (tics); nlabels = numel (labels); fprintf (plot_stream, "set format %s \"%%s\";\n", ax); - fprintf (plot_stream, "set %stics (", ax); + fprintf (plot_stream, "set %stics %s (", ax, colorspec); for i = 1:ntics fprintf (plot_stream, " \"%s\" %g", labels(k++), tics(i)) if (i < ntics) @@ -1589,7 +1595,38 @@ endif else fprintf (plot_stream, "set format %s \"%%g\";\n", ax); - fprintf (plot_stream, "set %stics;\n", ax); + fprintf (plot_stream, "set %stics %s;\n", ax, colorspec); + endif +endfunction + +function colorspec = get_text_colorspec (color) + persistent have_newer_gnuplot ... + = compare_versions (__gnuplot_version__ (), "4.0", ">"); + + if (have_newer_gnuplot) + colorspec = sprintf ("textcolor rgb \"#%02x%02x%02x\"", + round (255*color)); + else + if (isequal (color, [0,0,0])) + typ = -1; + elseif (isequal (color, [1,0,0])) + typ = 1; + elseif (isequal (color, [0,1,0])) + typ = 2; + elseif (isequal (color, [0,0,1])) + typ = 3; + elseif (isequal (color, [1,0,1])) + typ = 4; + elseif (isequal (color, [0,1,1])) + typ = 5; + elseif (isequal (color, [1,1,1])) + typ = -1; + elseif (isequal (color, [1,1,0])) + typ = 7; + else + typ = -1; + endif + colorspec = sprintf ("textcolor lt %d", typ); endif endfunction
--- a/scripts/plot/xlabel.m +++ b/scripts/plot/xlabel.m @@ -21,7 +21,9 @@ ## @deftypefn {Function File} {} xlabel (@var{string}) ## @deftypefnx {Function File} {} ylabel (@var{string}) ## @deftypefnx {Function File} {} zlabel (@var{string}) -## Specify x, y, and z axis labels for the current figure. +## @deftypefnx {Function File} {} xlabel (@var{h}, @var{string}) +## Specify x, y, and z axis labels for the current figure. If @var{h} is +## specified then label the axis defined by @var{h}. ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, ## bar, stairs, ylabel, title} ## @end deftypefn @@ -30,14 +32,30 @@ function h = xlabel (varargin) - if (rem (nargin, 2) == 1) - if (nargout > 0) - h = __axis_label__ ("xlabel", varargin{:}); - else - __axis_label__ ("xlabel", varargin{:}); + if (isscalar (varargin{1}) && ishandle (varargin{1})) + ax = varargin {1}; + if (! strcmp (get (ax, "type"), "axes")) + error ("xlabel: expecting first argument to be an axes object"); + endif + if (rem (nargin, 2) == 1) + print_usage (); endif + oldh = gca (); + unwind_protect + axes (ax); + tmp = __axis_label__ ("xlabel", varargin{2:end}); + unwind_protect_cleanup + axes (oldh); + end_unwind_protect else - print_usage (); + if (rem (nargin, 2) != 1) + print_usage (); + endif + tmp = __axis_label__ ("xlabel", varargin{1:end}); + endif + + if (nargout > 0) + h = tmp; endif endfunction
--- a/scripts/plot/ylabel.m +++ b/scripts/plot/ylabel.m @@ -19,6 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} ylabel (@var{string}) +## @deftypefnx {Function File} {} ylabel (@var{h}, @var{string}) ## See xlabel. ## @end deftypefn @@ -26,14 +27,30 @@ function h = ylabel (varargin) - if (rem (nargin, 2) == 1) - if (nargout > 0) - h = __axis_label__ ("ylabel", varargin{:}); - else - __axis_label__ ("ylabel", varargin{:}); + if (isscalar (varargin{1}) && ishandle (varargin{1})) + ax = varargin {1}; + if (! strcmp (get (ax, "type"), "axes")) + error ("ylabel: expecting first argument to be an axes object"); + endif + if (rem (nargin, 2) == 1) + print_usage (); endif + oldh = gca (); + unwind_protect + axes (ax); + tmp = __axis_label__ ("ylabel", varargin{2:end}); + unwind_protect_cleanup + axes (oldh); + end_unwind_protect else - print_usage (); + if (rem (nargin, 2) != 1) + print_usage (); + endif + tmp = __axis_label__ ("ylabel", varargin{1:end}); + endif + + if (nargout > 0) + h = tmp; endif endfunction
--- a/scripts/plot/zlabel.m +++ b/scripts/plot/zlabel.m @@ -19,6 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} zlabel (@var{string}) +## @deftypefnx {Function File} {} zlabel (@var{h}, @var{string}) ## See xlabel. ## @end deftypefn @@ -26,14 +27,30 @@ function h = zlabel (varargin) - if (rem (nargin, 2) == 1) - if (nargout > 0) - h = __axis_label__ ("zlabel", varargin{:}); - else - __axis_label__ ("zlabel", varargin{:}); + if (isscalar (varargin{1}) && ishandle (varargin{1})) + ax = varargin {1}; + if (! strcmp (get (ax, "type"), "axes")) + error ("zlabel: expecting first argument to be an axes object"); + endif + if (rem (nargin, 2) == 1) + print_usage (); endif + oldh = gca (); + unwind_protect + axes (ax); + tmp = __axis_label__ ("zlabel", varargin{2:end}); + unwind_protect_cleanup + axes (oldh); + end_unwind_protect else - print_usage (); + if (rem (nargin, 2) != 1) + print_usage (); + endif + tmp = __axis_label__ ("zlabel", varargin{1:end}); + endif + + if (nargout > 0) + h = tmp; endif endfunction
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2007-11-26 David Bateman <dbateman@free.fr> + * graphics.cc (class axes): Add the {x|y|z}color color property. + * graphics.h.in (class axes): ditto. + * ov-base.cc (Vsparse_auto_mutate, Fsparse_auto_mutate): New internal variable and built-in function to set it. * ov-base.h (extern bool Vsparse_auto_mutate): Export internal
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -1101,6 +1101,9 @@ xticklabelmode ("auto"), yticklabelmode ("auto"), zticklabelmode ("auto"), + xcolor (), + ycolor (), + zcolor (), xscale ("linear"), yscale ("linear"), zscale ("linear"), @@ -1290,6 +1293,12 @@ set_yticklabelmode (val); else if (name.compare ("zticklabelmode")) set_zticklabelmode (val); + else if (name.compare ("xcolor")) + set_xcolor (val); + else if (name.compare ("ycolor")) + set_ycolor (val); + else if (name.compare ("zcolor")) + set_zcolor (val); else if (name.compare ("xscale")) set_xscale (val); else if (name.compare ("yscale")) @@ -1375,6 +1384,9 @@ xticklabelmode = "auto"; yticklabelmode = "auto"; zticklabelmode = "auto"; + xcolor = color_property ("black"); + ycolor = color_property ("black"); + zcolor = color_property ("black"); xscale = "linear"; yscale = "linear"; zscale = "linear"; @@ -1495,6 +1507,9 @@ m.assign ("xticklabelmode", xticklabelmode); m.assign ("yticklabelmode", yticklabelmode); m.assign ("zticklabelmode", zticklabelmode); + m.assign ("xcolor", xcolor); + m.assign ("ycolor", ycolor); + m.assign ("zcolor", zcolor); m.assign ("xscale", xscale); m.assign ("yscale", yscale); m.assign ("zscale", zscale); @@ -1603,6 +1618,12 @@ retval = yticklabelmode; else if (name.compare ("zticklabelmode")) retval = zticklabelmode; + else if (name.compare ("xcolor")) + retval = xcolor; + else if (name.compare ("ycolor")) + retval = ycolor; + else if (name.compare ("zcolor")) + retval = zcolor; else if (name.compare ("xscale")) retval = xscale; else if (name.compare ("yscale")) @@ -1713,6 +1734,9 @@ m["xticklabelmode"] = "auto"; m["yticklabelmode"] = "auto"; m["zticklabelmode"] = "auto"; + m["xcolor"] = color_property ("black"); + m["ycolor"] = color_property ("black"); + m["zcolor"] = color_property ("black"); m["xscale"] = "linear"; m["yscale"] = "linear"; m["zscale"] = "linear";