Mercurial > hg > octave-nkf
comparison scripts/plot/__errplot__.m @ 8258:2b408bbd8904
Add error bar series
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 22 Oct 2008 11:21:28 +0100 |
parents | a1dbe9d80eee |
children | dad9a322c639 |
comparison
equal
deleted
inserted
replaced
8257:79c874fe5100 | 8258:2b408bbd8904 |
---|---|
27 | 27 |
28 if (nargin < 4 || nargin > 8) # at least two data arguments needed | 28 if (nargin < 4 || nargin > 8) # at least two data arguments needed |
29 print_usage (); | 29 print_usage (); |
30 endif | 30 endif |
31 | 31 |
32 [fmt, key] = __pltopt__ ("__errplot__", fstr); | 32 fstr |
33 [fmt, key] = __pltopt__ ("__errplot__", fstr) | |
33 | 34 |
34 [len, nplots] = size (a1); | 35 [len, nplots] = size (a1); |
36 h = []; | |
35 | 37 |
36 for i = 1:nplots | 38 for i = 1:nplots |
37 ## Set the plot type based on linestyle. | 39 ## Set the plot type based on linestyle. |
38 if (fmt.linestyle == "~") | 40 |
41 if (strcmp (fmt.linestyle, "~")) | |
39 ifmt = "yerr"; | 42 ifmt = "yerr"; |
40 elseif (fmt.linestyle == ">") | 43 elseif (strcmp (fmt.linestyle, ">")) |
41 ifmt = "xerr"; | 44 ifmt = "xerr"; |
42 elseif (fmt.linestyle == "~>") | 45 elseif (strcmp (fmt.linestyle, "~>")) |
43 ifmt = "xyerr"; | 46 ifmt = "xyerr"; |
44 elseif (fmt.linestyle == "#") | 47 elseif (strcmp (fmt.linestyle, "#")) |
45 ifmt = "box"; | 48 ifmt = "box"; |
46 elseif (fmt.linestyle == "#~") | 49 elseif (strcmp (fmt.linestyle, "#~")) |
47 ifmt = "boxy"; | 50 ifmt = "boxy"; |
48 elseif (fmt.linestyle == "#~>") | 51 elseif (strcmp (fmt.linestyle, "#~>")) |
49 ifmt = "boxxy"; | 52 ifmt = "boxxy"; |
50 else | 53 else |
51 print_usage (); | 54 print_usage (); |
52 endif | 55 endif |
53 | 56 |
54 h = __line__ (p); | 57 hg = hggroup ("parent", p); |
58 h = [h; hg]; | |
59 args = __add_datasource__ ("__errplot__", hg, | |
60 {"x", "y", "l", "u", "xl", "xu"}); | |
61 | |
62 if (isempty (fmt.color)) | |
63 hl = __line__ (hg, "color", __next_line_color__ ()); | |
64 else | |
65 hl = __line__ (hg, "color", fmt.color); | |
66 endif | |
67 | |
68 ## FIXME | |
69 ## Note the below adds the errorbar data directly as ldata, etc | |
70 ## properties of the line objects, as gnuplot can handle this. | |
71 ## Matlab has the errorbar part of the plot as a special line object | |
72 ## with embedded NaNs that draws the three segments of the bar | |
73 ## separately. Should we duplicate Matlab's behavior and stop using the | |
74 ## ldata, etc properties of the line objects that are Octace specific? | |
55 | 75 |
56 switch (nargin - 2) | 76 switch (nargin - 2) |
77 case 1 | |
78 error ("error plot requires 2, 3, 4 or 6 columns"); | |
57 case 2 | 79 case 2 |
58 set (h, "xdata", (1:len)'); | 80 set (hl, "xdata", (1:len)'); |
59 set (h, "ydata", a1(:,i)); | 81 set (hl, "ydata", a1(:,i)); |
60 set (h, "ldata", a2(:,i)); | 82 set (hl, "ldata", a2(:,i)); |
61 set (h, "udata", a2(:,i)); | 83 set (hl, "udata", a2(:,i)); |
62 case 3 | 84 case 3 |
63 set (h, "xdata", a1(:,i)); | 85 set (hl, "xdata", a1(:,i)); |
64 set (h, "ydata", a2(:,i)); | 86 set (hl, "ydata", a2(:,i)); |
65 set (h, "ldata", a3(:,i)); | 87 set (hl, "ldata", a3(:,i)); |
66 set (h, "udata", a3(:,i)); | 88 set (hl, "udata", a3(:,i)); |
67 case 4 | 89 case 4 |
68 set (h, "xdata", a1(:,i)); | 90 set (hl, "xdata", a1(:,i)); |
69 set (h, "ydata", a2(:,i)); | 91 set (hl, "ydata", a2(:,i)); |
70 | 92 |
71 if (index (ifmt, "boxxy") || index (ifmt, "xyerr")) | 93 if (index (ifmt, "boxxy") || index (ifmt, "xyerr")) |
72 set (h, "xldata", a3(:,i)); | 94 set (hl, "xldata", a3(:,i)); |
73 set (h, "xudata", a3(:,i)); | 95 set (hl, "xudata", a3(:,i)); |
74 set (h, "ldata", a4(:,i)); | 96 set (hl, "ldata", a4(:,i)); |
75 set (h, "udata", a4(:,i)); | 97 set (hl, "udata", a4(:,i)); |
76 elseif (index (ifmt, "xerr")) | 98 elseif (index (ifmt, "xerr")) |
77 set (h, "xldata", a3(:,i)); | 99 set (hl, "xldata", a3(:,i)); |
78 set (h, "xudata", a4(:,i)); | 100 set (hl, "xudata", a4(:,i)); |
79 else | 101 else |
80 set (h, "ldata", a3(:,i)); | 102 set (hl, "ldata", a3(:,i)); |
81 set (h, "udata", a4(:,i)); | 103 set (hl, "udata", a4(:,i)); |
82 endif | 104 endif |
83 case 5 | 105 case 5 |
84 error ("error plot requires 2, 3, 4 or 6 columns"); | 106 error ("error plot requires 2, 3, 4 or 6 columns"); |
85 case 6 | 107 case 6 |
86 set (h, "xdata", a1(:,i)); | 108 set (hl, "xdata", a1(:,i)); |
87 set (h, "ydata", a2(:,i)); | 109 set (hl, "ydata", a2(:,i)); |
88 set (h, "xldata", a3(:,i)); | 110 set (hl, "xldata", a3(:,i)); |
89 set (h, "xudata", a4(:,i)); | 111 set (hl, "xudata", a4(:,i)); |
90 set (h, "ldata", a5(:,i)); | 112 set (hl, "ldata", a5(:,i)); |
91 set (h, "udata", a6(:,i)); | 113 set (hl, "udata", a6(:,i)); |
92 endswitch | 114 endswitch |
115 | |
116 addproperty ("color", hg, "linecolor", get (hl, "color")); | |
117 addproperty ("linewidth", hg, "linelinewidth", get (hl, "linewidth")); | |
118 addproperty ("linestyle", hg, "linelinestyle", get (hl, "linestyle")); | |
119 addproperty ("marker", hg, "linemarker", get (hl, "marker")); | |
120 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", | |
121 get (hl, "markerfacecolor")); | |
122 addproperty ("markeredgecolor", hg, "linemarkerfacecolor", | |
123 get (hl, "markeredgecolor")); | |
124 addproperty ("markersize", hg, "linemarkersize", | |
125 get (hl, "markersize")); | |
126 | |
127 addlistener (hg, "color", @update_props); | |
128 addlistener (hg, "linewidth", @update_props); | |
129 addlistener (hg, "linestyle", @update_props); | |
130 addlistener (hg, "marker", @update_props); | |
131 addlistener (hg, "markerfacecolor", @update_props); | |
132 addlistener (hg, "markersize", @update_props); | |
133 | |
134 addproperty ("xdata", hg, "data", get (hl, "xdata")); | |
135 addproperty ("ydata", hg, "data", get (hl, "ydata")); | |
136 addproperty ("ldata", hg, "data", get (hl, "ldata")); | |
137 addproperty ("udata", hg, "data", get (hl, "udata")); | |
138 addproperty ("xldata", hg, "data", get (hl, "xldata")); | |
139 addproperty ("xudata", hg, "data", get (hl, "xudata")); | |
140 | |
141 addlistener (hg, "xdata", @update_data); | |
142 addlistener (hg, "ydata", @update_data); | |
143 addlistener (hg, "ldata", @update_data); | |
144 addlistener (hg, "udata", @update_data); | |
145 addlistener (hg, "xldata", @update_data); | |
146 addlistener (hg, "xudata", @update_data); | |
147 | |
148 __line__ (hg, "xdata", get (hl, "xdata"), | |
149 "ydata", get (hl, "ydata"), | |
150 "color", get (hl, "color"), | |
151 "linewidth", get (hl, "linewidth"), | |
152 "linestyle", get (hl, "linestyle"), | |
153 "marker", "none", "parent", hg); | |
93 endfor | 154 endfor |
94 | 155 |
95 endfunction | 156 endfunction |
157 | |
158 function update_props (h, d) | |
159 set (get (h, "children"), "color", get (h, "color"), | |
160 "linewidth", get (h, "linewidth"), "linestyle", get (h, "linestyle"), | |
161 "marker", get (h, "marker"), "markersize", get (h, "markersize"), | |
162 "markerfacecolor", get (h, "markerfacecolor"), | |
163 "markeredgecolor", get (h, "markeredgecolor")); | |
164 endfunction | |
165 | |
166 function update_data (h, d) | |
167 x = get (h, "xdata"); | |
168 y = get (h, "ydata"); | |
169 l = get (h, "ldata"); | |
170 u = get (h, "udata"); | |
171 xl = get (h, "xldata"); | |
172 xu = get (h, "xudata"); | |
173 | |
174 kids = get (h, "children"); | |
175 set (kids(1), "xdata", x, "ydata", y); | |
176 set (kids(2), "xdata", x, "ydata", y, "ldata", l, "udata", u, | |
177 "xldata", xl, "xudata", xu); | |
178 endfunction |