Mercurial > hg > octave-nkf
annotate scripts/plot/refreshdata.m @ 14237:11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Add clf() to all demos using plot features to get reproducibility.
Use 64 as input to all colormaps (jet (64)) to get reproducibility.
* bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m,
interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m,
griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m,
copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m,
ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m,
condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m,
compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m,
ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m,
ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m,
fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m,
pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m,
plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m,
rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m,
semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m,
subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m,
triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m,
waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m,
bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m,
example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m,
weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 20 Jan 2012 12:59:53 -0800 |
parents | 72c96de7a403 |
children | 4506eade9f04 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 2008-2012 David Bateman |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 ## your option) any later version. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 ## General Public License for more details. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
9316
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
20 ## @deftypefn {Function File} {} refreshdata () |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 ## @deftypefnx {Function File} {} refreshdata (@var{h}) |
9316
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
22 ## @deftypefnx {Function File} {} refreshdata (@var{h}, @var{workspace}) |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
23 ## Evaluate any @samp{datasource} properties of the current figure and update |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
24 ## the plot if the corresponding data has changed. If called with one or more |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
25 ## arguments @var{h} is a scalar or array of figure handles to refresh. The |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
26 ## optional second argument @var{workspace} can take the following values. |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 ## |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
28 ## @table @asis |
9316
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
29 ## @item "base" |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
30 ## Evaluate the datasource properties in the base workspace. (default). |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
31 ## |
9316
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
32 ## @item "caller" |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
33 ## Evaluate the datasource properties in the workspace of the function |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
34 ## that called @code{refreshdata}. |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
35 ## @end table |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
36 ## |
c539ec5726e7
Update some of Advanced Plotting documentation.
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
37 ## An example of the use of @code{refreshdata} is: |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 ## @example |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 ## @group |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 ## x = 0:0.1:10; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 ## y = sin (x); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 ## plot (x, y, "ydatasource", "y"); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 ## for i = 1 : 100 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
45 ## pause (0.1) |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 ## y = sin (x + 0.1 * i); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
47 ## refreshdata (); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 ## endfor |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 ## @end group |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
50 ## @end example |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
51 ## @end deftypefn |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
53 function refreshdata (h, workspace) |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
54 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 if (nargin == 0) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 h = gcf (); |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
57 workspace = "base"; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
58 else |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
59 if (iscell (h)) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
60 h = [h{:}]; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
61 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
62 if (!all (ishandle (h)) || !all (strcmp (get (h, "type"), "figure"))) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
63 error ("refreshdata: expecting a list of figure handles"); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
64 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
65 if (nargin < 2) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
66 workspace = "base"; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
67 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
68 if ( !ischar (workspace) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
69 || !(strcmpi (workspace, "base") |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
70 || strcmpi (workspace, "caller"))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11469
diff
changeset
|
71 error ("refreshdata: expecting WORKSPACE to be \"base\" or ""caller\""); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
72 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
73 workspace = tolower (workspace); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
74 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
75 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
76 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
77 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
78 h = findall (h); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
79 objs = []; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
80 props = {}; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
81 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
82 for i = 1 : numel (h) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
83 obj = get (h (i)); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
84 fldnames = fieldnames (obj); |
11032
c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
85 m = regexpi (fieldnames(obj), '^.+datasource$', "match"); |
12931
cefd568ea073
Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
86 idx = ! cellfun ("isempty", m); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
87 if (any (idx)) |
10439
59967776ed4a
make refreshdata work again
John W. Eaton <jwe@octave.org>
parents:
9316
diff
changeset
|
88 tmp = m(idx); |
59967776ed4a
make refreshdata work again
John W. Eaton <jwe@octave.org>
parents:
9316
diff
changeset
|
89 props = [props; {vertcat(tmp{:})}]; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
90 objs = [objs ; h(i)]; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
92 endfor |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
93 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
94 for i = 1 : length (objs) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
95 for j = 1 : length (props {i}) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 expr = get (objs(i), props{i}{j}); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 if (!isempty (expr)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11032
diff
changeset
|
98 val = evalin (workspace, expr); |
10549 | 99 prop = props{i}{j}(1:end-6); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
100 if (! isequal (get (objs(i), prop), val)) |
10549 | 101 set (objs(i), props{i}{j}(1:end-6), val); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
102 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
103 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
104 endfor |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
105 endfor |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
107 endfunction |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
108 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
109 |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
110 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
111 %! clf; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
112 %! x = 0:0.1:10; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
113 %! y = sin (x); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
114 %! plot (x, y, "ydatasource", "y"); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
115 %! for i = 1 : 100 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
116 %! pause (0.1); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
117 %! y = sin (x + 0.1 * i); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 %! refreshdata (gcf (), "caller"); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
119 %! endfor |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
120 |