Mercurial > hg > octave-nkf
annotate scripts/plot/private/__errplot__.m @ 10573:d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 26 Apr 2010 14:33:54 +0200 |
parents | 95c3e38098bf |
children | 3eba2cc7cbda |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
7017 | 2 ## Teemu Ikonen |
3718 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3718 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3718 | 19 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
20 ## -*- texinfo -*- |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
21 ## @deftypefn {Function File} {@var{h} =} __errplot__ (@var{fstr}, @var{p}, @dots{}) |
6895 | 22 ## Undocumented internal function. |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
23 ## @end deftypefn |
5720 | 24 |
3718 | 25 ## Created: 18.7.2000 |
26 ## Author: Teemu Ikonen <tpikonen@pcu.helsinki.fi> | |
27 ## Keywords: errorbar, plotting | |
28 | |
6405 | 29 function h = __errplot__ (fstr, p, a1, a2, a3, a4, a5, a6) |
5406 | 30 |
6257 | 31 if (nargin < 4 || nargin > 8) # at least two data arguments needed |
6046 | 32 print_usage (); |
4897 | 33 endif |
4007 | 34 |
8259
dad9a322c639
Remove debugging from previous patch
David Bateman <dbateman@free.fr>
parents:
8258
diff
changeset
|
35 [fmt, key] = __pltopt__ ("__errplot__", fstr); |
6146 | 36 |
6172 | 37 [len, nplots] = size (a1); |
8258 | 38 h = []; |
4007 | 39 |
4897 | 40 for i = 1:nplots |
6736 | 41 ## Set the plot type based on linestyle. |
8258 | 42 |
43 if (strcmp (fmt.linestyle, "~")) | |
6736 | 44 ifmt = "yerr"; |
8258 | 45 elseif (strcmp (fmt.linestyle, ">")) |
6736 | 46 ifmt = "xerr"; |
8258 | 47 elseif (strcmp (fmt.linestyle, "~>")) |
6736 | 48 ifmt = "xyerr"; |
8258 | 49 elseif (strcmp (fmt.linestyle, "#")) |
6736 | 50 ifmt = "box"; |
8258 | 51 elseif (strcmp (fmt.linestyle, "#~")) |
6736 | 52 ifmt = "boxy"; |
8258 | 53 elseif (strcmp (fmt.linestyle, "#~>")) |
6736 | 54 ifmt = "boxxy"; |
55 else | |
56 print_usage (); | |
57 endif | |
58 | |
8258 | 59 hg = hggroup ("parent", p); |
60 h = [h; hg]; | |
61 args = __add_datasource__ ("__errplot__", hg, | |
10549 | 62 {"x", "y", "l", "u", "xl", "xu"}); |
8258 | 63 |
64 if (isempty (fmt.color)) | |
65 hl = __line__ (hg, "color", __next_line_color__ ()); | |
66 else | |
67 hl = __line__ (hg, "color", fmt.color); | |
68 endif | |
69 | |
8506 | 70 ## FIXME -- note the code below adds the errorbar data directly as |
71 ## ldata, etc properties of the line objects, as gnuplot can handle | |
72 ## this. Matlab has the errorbar part of the plot as a special line | |
73 ## object with embedded NaNs that draws the three segments of the | |
74 ## bar separately. Should we duplicate Matlab's behavior and stop | |
75 ## using the ldata, etc. properties of the line objects that are | |
76 ## Octace specific? | |
6736 | 77 |
6257 | 78 switch (nargin - 2) |
8258 | 79 case 1 |
10549 | 80 error ("error plot requires 2, 3, 4 or 6 columns"); |
4897 | 81 case 2 |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
82 if (index (ifmt, "xerr")) |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
83 set (hl, "xdata", (1:len)', "ydata", a1(:,i), "xldata", a2(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
84 "xudata", a2(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
85 elseif (index (ifmt, "yerr")) |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
86 set (hl, "xdata", (1:len)', "ydata", a1(:,i), "ldata", a2(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
87 "udata", a2(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
88 else |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
89 error ("2 column errorplot is only valid or xerr or yerr"); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
90 endif |
4897 | 91 case 3 |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
92 if (index (ifmt, "boxxy") || index (ifmt, "xyerr")) |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
93 set (hl, "xdata", (1:len)', "ydata", a1(:,i), "xldata", a2(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
94 "xudata", a2(:,i), "ldata", a3(:,i), "udata", a3(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
95 elseif (index (ifmt, "xerr")) |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
96 set (hl, "xdata", a1(:,i), "ydata", a2(:,i), "xldata", a3(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
97 "xudata", a3(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
98 else |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
99 set (hl, "xdata", a1(:,i), "ydata", a2(:,i), "ldata", a3(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
100 "udata", a3(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
101 endif |
4897 | 102 case 4 |
10549 | 103 if (index (ifmt, "boxxy") || index (ifmt, "xyerr")) |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
104 set (hl, "xdata", a1(:,i), "ydata", a2(:,i), "xldata", a3(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
105 "xudata", a3(:,i), "ldata", a4(:,i), "udata", a4(:,i)); |
10549 | 106 elseif (index (ifmt, "xerr")) |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
107 set (hl, "xdata", a1(:,i), "ydata", a2(:,i), "xldata", a3(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
108 "xudata", a4(:,i)); |
10549 | 109 else |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
110 set (hl, "xdata", a1(:,i), "ydata", a2(:,i), "ldata", a3(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
111 "udata", a4(:,i)); |
10549 | 112 endif |
4897 | 113 case 5 |
10549 | 114 error ("error plot requires 2, 3, 4 or 6 columns"); |
4897 | 115 case 6 |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
116 if (index (ifmt, "boxxy") || index (ifmt, "xyerr")) |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
117 set (hl, "xdata", a1(:,i), "ydata", a2(:,i), "xldata", a3(:,i), |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
118 "xudata", a4(:,i), "ldata", a5(:,i), "udata", a6(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
119 else |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
120 error ("error plot with 6 columns only valid for boxxy and xyerr"); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
121 endif |
4897 | 122 endswitch |
8258 | 123 |
124 addproperty ("color", hg, "linecolor", get (hl, "color")); | |
125 addproperty ("linewidth", hg, "linelinewidth", get (hl, "linewidth")); | |
126 addproperty ("linestyle", hg, "linelinestyle", get (hl, "linestyle")); | |
127 addproperty ("marker", hg, "linemarker", get (hl, "marker")); | |
128 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", | |
10549 | 129 get (hl, "markerfacecolor")); |
8258 | 130 addproperty ("markeredgecolor", hg, "linemarkerfacecolor", |
10549 | 131 get (hl, "markeredgecolor")); |
8258 | 132 addproperty ("markersize", hg, "linemarkersize", |
10549 | 133 get (hl, "markersize")); |
8258 | 134 |
135 addlistener (hg, "color", @update_props); | |
136 addlistener (hg, "linewidth", @update_props); | |
137 addlistener (hg, "linestyle", @update_props); | |
138 addlistener (hg, "marker", @update_props); | |
139 addlistener (hg, "markerfacecolor", @update_props); | |
140 addlistener (hg, "markersize", @update_props); | |
141 | |
142 addproperty ("xdata", hg, "data", get (hl, "xdata")); | |
143 addproperty ("ydata", hg, "data", get (hl, "ydata")); | |
144 addproperty ("ldata", hg, "data", get (hl, "ldata")); | |
145 addproperty ("udata", hg, "data", get (hl, "udata")); | |
146 addproperty ("xldata", hg, "data", get (hl, "xldata")); | |
147 addproperty ("xudata", hg, "data", get (hl, "xudata")); | |
148 | |
149 addlistener (hg, "xdata", @update_data); | |
150 addlistener (hg, "ydata", @update_data); | |
151 addlistener (hg, "ldata", @update_data); | |
152 addlistener (hg, "udata", @update_data); | |
153 addlistener (hg, "xldata", @update_data); | |
154 addlistener (hg, "xudata", @update_data); | |
155 | |
156 __line__ (hg, "xdata", get (hl, "xdata"), | |
10549 | 157 "ydata", get (hl, "ydata"), |
158 "color", get (hl, "color"), | |
159 "linewidth", get (hl, "linewidth"), | |
160 "linestyle", get (hl, "linestyle"), | |
161 "marker", "none", "parent", hg); | |
5406 | 162 endfor |
163 | |
4007 | 164 endfunction |
8258 | 165 |
166 function update_props (h, d) | |
167 set (get (h, "children"), "color", get (h, "color"), | |
168 "linewidth", get (h, "linewidth"), "linestyle", get (h, "linestyle"), | |
169 "marker", get (h, "marker"), "markersize", get (h, "markersize"), | |
170 "markerfacecolor", get (h, "markerfacecolor"), | |
171 "markeredgecolor", get (h, "markeredgecolor")); | |
172 endfunction | |
173 | |
174 function update_data (h, d) | |
175 x = get (h, "xdata"); | |
176 y = get (h, "ydata"); | |
177 l = get (h, "ldata"); | |
178 u = get (h, "udata"); | |
179 xl = get (h, "xldata"); | |
180 xu = get (h, "xudata"); | |
181 | |
182 kids = get (h, "children"); | |
183 set (kids(1), "xdata", x, "ydata", y); | |
184 set (kids(2), "xdata", x, "ydata", y, "ldata", l, "udata", u, | |
185 "xldata", xl, "xudata", xu); | |
186 endfunction |