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