Mercurial > hg > octave-lyh
annotate scripts/plot/private/__errplot__.m @ 10580:1479b93ee655
Respect linestyleorder in errorbar plots
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 28 Apr 2010 00:23:57 +0200 |
parents | 384c514bbae2 |
children | e2a4e87b900c |
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 |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
43 if (strcmp (fmt.errorstyle, "~")) |
6736 | 44 ifmt = "yerr"; |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
45 elseif (strcmp (fmt.errorstyle, ">")) |
6736 | 46 ifmt = "xerr"; |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
47 elseif (strcmp (fmt.errorstyle, "~>")) |
6736 | 48 ifmt = "xyerr"; |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
49 elseif (strcmp (fmt.errorstyle, "#")) |
6736 | 50 ifmt = "box"; |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
51 elseif (strcmp (fmt.errorstyle, "#~")) |
6736 | 52 ifmt = "boxy"; |
8258 | 53 elseif (strcmp (fmt.linestyle, "#~>")) |
6736 | 54 ifmt = "boxxy"; |
55 else | |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
56 ifmt = "~"; |
10576
384c514bbae2
Allow setting of the markers in errorbar linestyles
David Bateman <dbateman@free.fr>
parents:
10575
diff
changeset
|
57 endif |
384c514bbae2
Allow setting of the markers in errorbar linestyles
David Bateman <dbateman@free.fr>
parents:
10575
diff
changeset
|
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 |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
64 if (isempty (fmt.marker) && isempty (fmt.linestyle)) |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
65 [linestyle, marker] = __next_line_style__ (); |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
66 if (isempty (fmt.color)) |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
67 hl = __line__ (hg, "linestyle", linestyle, "marker", marker, |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
68 "color", __next_line_color__ ()) |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
69 else |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
70 hl = __line__ (hg, "linestyle", linestyle, "marker", marker, |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
71 "color", fmt.color) |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
72 endif |
8258 | 73 else |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
74 if (isempty (fmt.color)) |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
75 hl = __line__ (hg, "linestyle", fmt.linestyle, "marker", fmt.marker, |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
76 "color", __next_line_color__ ()) |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
77 else |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
78 hl = __line__ (hg, "linestyle", fmt.linestyle, "marker", fmt.marker, |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
79 "color", fmt.color) |
10575
3eba2cc7cbda
Allow matlab style linestyles in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10573
diff
changeset
|
80 endif |
3eba2cc7cbda
Allow matlab style linestyles in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10573
diff
changeset
|
81 endif |
3eba2cc7cbda
Allow matlab style linestyles in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10573
diff
changeset
|
82 |
8506 | 83 ## FIXME -- note the code below adds the errorbar data directly as |
84 ## ldata, etc properties of the line objects, as gnuplot can handle | |
85 ## this. Matlab has the errorbar part of the plot as a special line | |
86 ## object with embedded NaNs that draws the three segments of the | |
87 ## bar separately. Should we duplicate Matlab's behavior and stop | |
88 ## using the ldata, etc. properties of the line objects that are | |
89 ## Octace specific? | |
6736 | 90 |
6257 | 91 switch (nargin - 2) |
8258 | 92 case 1 |
10549 | 93 error ("error plot requires 2, 3, 4 or 6 columns"); |
4897 | 94 case 2 |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
95 if (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", (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
|
97 "xudata", a2(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
98 elseif (index (ifmt, "yerr")) |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
99 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
|
100 "udata", a2(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
101 else |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
102 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
|
103 endif |
4897 | 104 case 3 |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
105 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
|
106 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
|
107 "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
|
108 elseif (index (ifmt, "xerr")) |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
109 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
|
110 "xudata", a3(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
111 else |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
112 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
|
113 "udata", a3(:,i)); |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
114 endif |
4897 | 115 case 4 |
10549 | 116 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
|
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", a3(:,i), "ldata", a4(:,i), "udata", a4(:,i)); |
10549 | 119 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
|
120 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
|
121 "xudata", a4(:,i)); |
10549 | 122 else |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
123 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
|
124 "udata", a4(:,i)); |
10549 | 125 endif |
4897 | 126 case 5 |
10549 | 127 error ("error plot requires 2, 3, 4 or 6 columns"); |
4897 | 128 case 6 |
10573
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
129 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
|
130 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
|
131 "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
|
132 else |
d8894a2d0a03
Allow x, xy and box errorbars with different plotting syntax
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
133 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
|
134 endif |
4897 | 135 endswitch |
8258 | 136 |
137 addproperty ("color", hg, "linecolor", get (hl, "color")); | |
138 addproperty ("linewidth", hg, "linelinewidth", get (hl, "linewidth")); | |
139 addproperty ("linestyle", hg, "linelinestyle", get (hl, "linestyle")); | |
140 addproperty ("marker", hg, "linemarker", get (hl, "marker")); | |
141 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", | |
10549 | 142 get (hl, "markerfacecolor")); |
8258 | 143 addproperty ("markeredgecolor", hg, "linemarkerfacecolor", |
10549 | 144 get (hl, "markeredgecolor")); |
8258 | 145 addproperty ("markersize", hg, "linemarkersize", |
10549 | 146 get (hl, "markersize")); |
8258 | 147 |
148 addlistener (hg, "color", @update_props); | |
149 addlistener (hg, "linewidth", @update_props); | |
150 addlistener (hg, "linestyle", @update_props); | |
151 addlistener (hg, "marker", @update_props); | |
152 addlistener (hg, "markerfacecolor", @update_props); | |
153 addlistener (hg, "markersize", @update_props); | |
154 | |
155 addproperty ("xdata", hg, "data", get (hl, "xdata")); | |
156 addproperty ("ydata", hg, "data", get (hl, "ydata")); | |
157 addproperty ("ldata", hg, "data", get (hl, "ldata")); | |
158 addproperty ("udata", hg, "data", get (hl, "udata")); | |
159 addproperty ("xldata", hg, "data", get (hl, "xldata")); | |
160 addproperty ("xudata", hg, "data", get (hl, "xudata")); | |
161 | |
162 addlistener (hg, "xdata", @update_data); | |
163 addlistener (hg, "ydata", @update_data); | |
164 addlistener (hg, "ldata", @update_data); | |
165 addlistener (hg, "udata", @update_data); | |
166 addlistener (hg, "xldata", @update_data); | |
167 addlistener (hg, "xudata", @update_data); | |
168 | |
169 __line__ (hg, "xdata", get (hl, "xdata"), | |
10549 | 170 "ydata", get (hl, "ydata"), |
171 "color", get (hl, "color"), | |
172 "linewidth", get (hl, "linewidth"), | |
173 "linestyle", get (hl, "linestyle"), | |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10576
diff
changeset
|
174 "marker", get (hl, "marker"), "parent", hg); |
5406 | 175 endfor |
176 | |
4007 | 177 endfunction |
8258 | 178 |
179 function update_props (h, d) | |
180 set (get (h, "children"), "color", get (h, "color"), | |
181 "linewidth", get (h, "linewidth"), "linestyle", get (h, "linestyle"), | |
182 "marker", get (h, "marker"), "markersize", get (h, "markersize"), | |
183 "markerfacecolor", get (h, "markerfacecolor"), | |
184 "markeredgecolor", get (h, "markeredgecolor")); | |
185 endfunction | |
186 | |
187 function update_data (h, d) | |
188 x = get (h, "xdata"); | |
189 y = get (h, "ydata"); | |
190 l = get (h, "ldata"); | |
191 u = get (h, "udata"); | |
192 xl = get (h, "xldata"); | |
193 xu = get (h, "xudata"); | |
194 | |
195 kids = get (h, "children"); | |
196 set (kids(1), "xdata", x, "ydata", y); | |
197 set (kids(2), "xdata", x, "ydata", y, "ldata", l, "udata", u, | |
198 "xldata", xl, "xudata", xu); | |
199 endfunction |