Mercurial > hg > octave-lojdl
changeset 6004:01556febbaaf
[project @ 2006-09-26 21:16:52 by jwe]
author | jwe |
---|---|
date | Tue, 26 Sep 2006 21:16:52 +0000 |
parents | 7f8e4f5e2eb7 |
children | b4351cfb5659 |
files | scripts/ChangeLog scripts/plot/__errplot__.m scripts/plot/__plt3__.m scripts/plot/__plt__.m scripts/plot/__setup_plot__.m scripts/plot/contour.m scripts/plot/mesh.m scripts/plot/plot3.m |
diffstat | 8 files changed, 239 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,20 @@ +2006-09-26 David Bateman <dbateman@free.fr> + + * __plt3__.m: Using global variables __plot_data__, + __plot_data_offset__ and __plot_command__ to store plots and + correctly handle multiplots, and hold state. Only accept a single + data parameter plus, using, format and with strings. Remove + setting of gnuplot parameters. + * __make_using_clause__.m: New function extracted from __plt__.m. + * __setup_plot__.m: Convert to a function and pass the plotting + command to use. + * __plt__.m: Change call to __setup_plot__ and __make_using_clause__. + * contour.m: Use unwind protect on the parametric state of plot + and __plt3__ instead of calling __gnuplot_splot__ directly. + * mesh.m: ditto. + * plot3.m: Error checking, setting of parametric state and + formation of matrix to plot moved from old __plt3__. + 2006-09-22 Michael Creel <michael.creel@uab.es> * deprecated/chisquare_pdf.m: Typo in documentation.
--- a/scripts/plot/__errplot__.m +++ b/scripts/plot/__errplot__.m @@ -37,7 +37,7 @@ __plot_globals__; - __setup_plot__; + __setup_plot__ ("__gnuplot_plot__"); if (nargin < 3 || nargin > 7) # at least three data arguments needed usage ("__errplot__ (fmt, arg1, ...)");
--- a/scripts/plot/__plt3__.m +++ b/scripts/plot/__plt3__.m @@ -33,34 +33,57 @@ ## David Bateman <dbateman@free.fr> ## May 25, 2006 -function __plt3__ (x, y, z, fmt) +function __plt3__ (x, usingstr, fmtstr, withstr) - if (isvector (x) && isvector (y)) - if (isvector (z)) - x = x(:); - y = y(:); - z = z(:); - elseif (length (x) == rows (z) && length (y) == columns (z)) - error ("plot3: [length(x), length(y)] must match size(z)"); - else - [x, y] = meshgrid (x, y); - endif + if (nargin < 2) + usingstr = ""; + endif + if (nargin < 3) + fmtstr = ""; + endif + if (nargin < 4) + withstr = ""; endif - if (any (size (x) != size (y)) || any (size (x) != size (z))) - error ("plot3: x, y, and z must have the same shape"); + __plot_globals__; + + __setup_plot__ ("__gnuplot_splot__"); + + j = __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__); + + __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j} = x; + + if (iscell (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j})) + for i = 1:length (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}) + if (! isempty(usingstr)) + length(usingstr) + usingstr = __make_using_clause__ (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}{i}); + endif + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d}{%d} %s %s", + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, + __plot_command_sep__, j, i, usingstr, fmtstr{i}); + __plot_command_sep__ = ",\\\n"; + endfor + else + if (! isempty(usingstr)) + length(usingstr) + usingstr = __make_using_clause__ (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}); + endif + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \ + = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d} %s %s %s", + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, + __plot_command_sep__, j, usingstr, fmtstr, withstr); + __plot_command_sep__ = ",\\\n"; endif - unwind_protect - __gnuplot_set__ parametric; - __gnuplot_raw__ ("set nohidden3d;\n"); + __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = ++j; - tmp = [([x; NaN*ones(1,size(x,2))])(:), ... - ([y; NaN*ones(1,size(y,2))])(:), ... - ([z; NaN*ones(1,size(z,2))])(:)]; + if (__multiplot_mode__) + __gnuplot_raw__ ("clear\n"); + endif - eval (sprintf ("__gnuplot_splot__ tmp %s\n", fmt)); - unwind_protect_cleanup - __gnuplot_set__ noparametric; - end_unwind_protect + if (! strcmp (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, "__gnuplot_splot__")) + eval (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}); + endif endfunction
--- a/scripts/plot/__plt__.m +++ b/scripts/plot/__plt__.m @@ -27,7 +27,7 @@ __plot_globals__; - __setup_plot__; + __setup_plot__ ("__gnuplot_plot__"); nargs = nargin (); @@ -93,7 +93,7 @@ if (have_data) if (iscell (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j})) for i = 1:length (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}) - usingstr = make_using_clause (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}{i}); + usingstr = __make_using_clause__ (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}{i}); __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \ = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d}{%d} %s %s", __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, @@ -101,7 +101,7 @@ __plot_command_sep__ = ",\\\n"; endfor else - usingstr = make_using_clause (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}); + usingstr = __make_using_clause__ (__plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{j}); __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} \ = sprintf ("%s%s __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}{%d} %s %s", __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__}, @@ -129,16 +129,4 @@ usage (msg); endif -## endfunction - -function usingstr = make_using_clause (x) - cols = columns (x); - if (cols > 0) - usingstr = strcat (gnuplot_command_using, " ($1)"); - for k = 2:cols - usingstr = sprintf ("%s:($%d)", usingstr, k); - endfor - else - usingstr = ""; - endif -## endfunction +endfunction
--- a/scripts/plot/__setup_plot__.m +++ b/scripts/plot/__setup_plot__.m @@ -17,16 +17,21 @@ ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ## 02110-1301, USA. -if (ishold ()) - if (isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__})) - __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = "__gnuplot_plot__"; +function __setup_plot__ (plotcmd) + + __plot_globals__ + + if (ishold ()) + if (isempty (__plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__})) + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = plotcmd; + __plot_command_sep__ = ""; + else + __plot_command_sep__ = ",\\\n"; + endif + else + __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = plotcmd; __plot_command_sep__ = ""; - else - __plot_command_sep__ = ",\\\n"; + __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = []; + __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1; endif -else - __plot_command__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = "__gnuplot_plot__"; - __plot_command_sep__ = ""; - __plot_data__{__current_figure__}{__multiplot_xi__,__multiplot_yi__} = []; - __plot_data_offset__{__current_figure__}(__multiplot_xi__,__multiplot_yi__) = 1; -endif +endfunction
--- a/scripts/plot/contour.m +++ b/scripts/plot/contour.m @@ -42,24 +42,29 @@ n = y; endif if (ismatrix (z)) - __gnuplot_raw__ ("set nosurface;\n"); - __gnuplot_raw__ ("set contour;\n"); - __gnuplot_raw__ ("set cntrparam bspline;\n"); - if (isscalar (n)) - command = sprintf ("set cntrparam levels %d;\n", n); - elseif (isvector (n)) - tmp = sprintf ("%f", n(1)); - for i = 2:length (n) - tmp = sprintf ("%s, %f", tmp, n(i)); - endfor - command = sprintf ("set cntrparam levels discrete %s;\n", tmp); - else - error ("contour: levels must be a scalar or vector") ; - endif - __gnuplot_raw__ (command); - __gnuplot_set__ parametric; - __gnuplot_raw__ ("set view 0, 0, 1, 1;\n"); - __gnuplot_splot__ z w l 1; + unwind_protect + __gnuplot_raw__ ("set nosurface;\n"); + __gnuplot_raw__ ("set contour;\n"); + __gnuplot_raw__ ("set cntrparam bspline;\n"); + if (isscalar (n)) + command = sprintf ("set cntrparam levels %d;\n", n); + elseif (isvector (n)) + tmp = sprintf ("%f", n(1)); + for i = 2:length (n) + tmp = sprintf ("%s, %f", tmp, n(i)); + endfor + command = sprintf ("set cntrparam levels discrete %s;\n", tmp); + else + error ("contour: levels must be a scalar or vector") ; + endif + __gnuplot_raw__ (command); + __gnuplot_set__ parametric; + __gnuplot_raw__ ("set view 0, 0, 1, 1;\n"); + __plt3__ (z, "", "", [gnuplot_command_with, " l 1"]); + unwind_protect_cleanup + __gnuplot_set__ noparametric; + end_unwind_protect + else error ("contour: z of contour (z, levels) must be a matrix"); endif @@ -102,24 +107,28 @@ error (size_msg); endif endif - __gnuplot_raw__ ("set nosurface;\n"); - __gnuplot_raw__ ("set contour;\n"); - __gnuplot_raw__ ("set cntrparam bspline;\n"); - if (isscalar (n)) - command = sprintf ("set cntrparam levels %d;\n", n); - elseif (isvector (n)) - tmp = sprintf ("%f", n(1)); - for i = 2:length (n) - tmp = sprintf ("%s, %f", tmp, n(i)); - endfor - command = sprintf ("set cntrparam levels discrete %s;\n", tmp); - else - error ("contour: levels must be a scalar or vector") ; - endif - __gnuplot_raw__ (command); - __gnuplot_set__ parametric; - __gnuplot_raw__ ("set view 0, 0, 1, 1;\n"); - __gnuplot_splot__ zz w l 1; + unwind_protect + __gnuplot_raw__ ("set nosurface;\n"); + __gnuplot_raw__ ("set contour;\n"); + __gnuplot_raw__ ("set cntrparam bspline;\n"); + if (isscalar (n)) + command = sprintf ("set cntrparam levels %d;\n", n); + elseif (isvector (n)) + tmp = sprintf ("%f", n(1)); + for i = 2:length (n) + tmp = sprintf ("%s, %f", tmp, n(i)); + endfor + command = sprintf ("set cntrparam levels discrete %s;\n", tmp); + else + error ("contour: levels must be a scalar or vector") ; + endif + __gnuplot_raw__ (command); + __gnuplot_set__ parametric; + __gnuplot_raw__ ("set view 0, 0, 1, 1;\n"); + __plt3__ (zz, "", "", [gnuplot_command_with, " l 1"]); + unwind_protect_cleanup + __gnuplot_set__ noparametric; + end_unwind_protect else error ("contour: x and y must be vectors and z must be a matrix"); endif
--- a/scripts/plot/mesh.m +++ b/scripts/plot/mesh.m @@ -46,7 +46,7 @@ __gnuplot_set__ noparametric; __gnuplot_raw__ ("set nologscale;\n"); __gnuplot_raw__ ("set view 60, 30, 1, ;\n"); - __gnuplot_splot__ (z'); + __plt3__ (z'); else error ("mesh: argument must be a matrix"); endif @@ -67,17 +67,20 @@ zz(:,i+2) = z(:,k); k++; endfor - __gnuplot_raw__ ("set hidden3d;\n"); - __gnuplot_raw__ ("set data style lines;\n"); - __gnuplot_raw__ ("set surface;\n"); - __gnuplot_raw__ ("set nocontour;\n"); - __gnuplot_raw__ ("set nologscale;\n"); - __gnuplot_set__ parametric; - __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); - __gnuplot_raw__ ("set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); - __gnuplot_raw__ ("set nocolorbox;\n"); - __gnuplot_splot__ zz with line palette; - __gnuplot_set__ noparametric; + unwind_protect + __gnuplot_raw__ ("set hidden3d;\n"); + __gnuplot_raw__ ("set data style lines;\n"); + __gnuplot_raw__ ("set surface;\n"); + __gnuplot_raw__ ("set nocontour;\n"); + __gnuplot_raw__ ("set nologscale;\n"); + __gnuplot_set__ parametric; + __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); + __gnuplot_raw__ ("set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"cyan\", 3 \"yellow\", 4 \"red\" , 5 \"dark-red\");\n"); + __gnuplot_raw__ ("set nocolorbox;\n"); + __plt3__ (zz, "", "", [gnuplot_command_with " line palette"]); + unwind_protect_cleanup + __gnuplot_set__ noparametric; + end_unwind_protect else msg = "mesh: rows (z) must be the same as length (y) and"; msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); @@ -97,15 +100,17 @@ zz(:,i+2) = z(:,k); k++; endfor - __gnuplot_raw__ ("set hidden3d;\n") - __gnuplot_raw__ ("set data style lines;\n"); - __gnuplot_raw__ ("set surface;\n"); - __gnuplot_raw__ ("set nocontour;\n"); - __gnuplot_raw__ ("set nologscale;\n"); - __gnuplot_set__ parametric; - __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); - __gnuplot_splot__ (zz); - __gnuplot_set__ noparametric; + unwind_protect + __gnuplot_raw__ ("set data style lines;\n"); + __gnuplot_raw__ ("set surface;\n"); + __gnuplot_raw__ ("set nocontour;\n"); + __gnuplot_raw__ ("set nologscale;\n"); + __gnuplot_set__ parametric; + __gnuplot_raw__ ("set view 60, 30, 1, 1;\n"); + __plt3__ (zz); + unwind_protect_cleanup + __gnuplot_set__ noparametric; + end_unwind_protect else error ("mesh: x, y, and z must have same dimensions"); endif
--- a/scripts/plot/plot3.m +++ b/scripts/plot/plot3.m @@ -200,7 +200,35 @@ endif endif fmt = __pltopt__ ("plot3", new); - __plt3__ (x, y, z, fmt); + + if (isvector (x) && isvector (y)) + if (isvector (z)) + x = x(:); + y = y(:); + z = z(:); + elseif (length (x) == rows (z) && length (y) == columns (z)) + error ("plot3: [length(x), length(y)] must match size(z)"); + else + [x, y] = meshgrid (x, y); + endif + endif + + if (any (size (x) != size (y)) || any (size (x) != size (z))) + error ("plot3: x, y, and z must have the same shape"); + endif + + unwind_protect + __gnuplot_raw__ ("set nohidden3d;\n") + __gnuplot_set__ parametric; + + __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... + ([y; NaN*ones(1,size(y,2))])(:), ... + ([z; NaN*ones(1,size(z,2))])(:)], "", fmt); + + unwind_protect_cleanup + __gnuplot_set__ noparametric; + end_unwind_protect + hold ("on"); x_set = 0; y_set = 0; @@ -215,7 +243,34 @@ z = new; z_set = 1; else - __plt3__ (x, y, z, ""); + if (isvector (x) && isvector (y)) + if (isvector (z)) + x = x(:); + y = y(:); + z = z(:); + elseif (length (x) == rows (z) && length (y) == columns (z)) + error ("plot3: [length(x), length(y)] must match size(z)"); + else + [x, y] = meshgrid (x, y); + endif + endif + + if (any (size (x) != size (y)) || any (size (x) != size (z))) + error ("plot3: x, y, and z must have the same shape"); + endif + + unwind_protect + __gnuplot_raw__ ("set nohidden3d;\n") + __gnuplot_set__ parametric; + + __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... + ([y; NaN*ones(1,size(y,2))])(:), ... + ([z; NaN*ones(1,size(z,2))])(:)]); + + unwind_protect_cleanup + __gnuplot_set__ noparametric; + end_unwind_protect + hold ("on"); x = new; y_set = 0; @@ -244,7 +299,33 @@ x = 1:columns(x); endif endif - __plt3__ (x, y, z, ""); + + if (isvector (x) && isvector (y)) + if (isvector (z)) + x = x(:); + y = y(:); + z = z(:); + elseif (length (x) == rows (z) && length (y) == columns (z)) + error ("plot3: [length(x), length(y)] must match size(z)"); + else + [x, y] = meshgrid (x, y); + endif + endif + + if (any (size (x) != size (y)) || any (size (x) != size (z))) + error ("plot3: x, y, and z must have the same shape"); + endif + + unwind_protect + __gnuplot_raw__ ("set nohidden3d;\n") + __gnuplot_set__ parametric; + + __plt3__ ([([x; NaN*ones(1,size(x,2))])(:), ... + ([y; NaN*ones(1,size(y,2))])(:), ... + ([z; NaN*ones(1,size(z,2))])(:)]); + unwind_protect_cleanup + __gnuplot_set__ noparametric; + end_unwind_protect endif unwind_protect_cleanup