comparison scripts/plot/draw/private/__errplot__.m @ 17572:7bb76a22cde1

maint: Split scripts/plot directory into 4 pieces. scripts/gui : user-interface functions scripts/plot/appearance : functions controlling plot appearance scripts/plot/draw : plotting functions which produce graphs scripts/plot/util : low-level plotting functions and utilities. * scripts/gui/guidata.m, scripts/gui/guihandles.m, scripts/gui/module.mk, scripts/gui/private/__file_filter__.m, scripts/gui/private/__fltk_file_filter__.m, scripts/gui/private/__is_function__.m, scripts/gui/private/__uigetdir_fltk__.m, scripts/gui/private/__uigetfile_fltk__.m, scripts/gui/private/__uiobject_split_args__.m, scripts/gui/private/__uiputfile_fltk__.m, scripts/gui/uicontextmenu.m, scripts/gui/uicontrol.m, scripts/gui/uigetdir.m, scripts/gui/uigetfile.m, scripts/gui/uimenu.m, scripts/gui/uipanel.m, scripts/gui/uipushtool.m, scripts/gui/uiputfile.m, scripts/gui/uiresume.m, scripts/gui/uitoggletool.m, scripts/gui/uitoolbar.m, scripts/gui/uiwait.m, scripts/gui/waitbar.m, scripts/gui/waitforbuttonpress.m: Moved from scripts/plot to scripts/gui * scripts/plot/appearance/__clabel__.m, scripts/plot/appearance/__getlegenddata__.m, scripts/plot/appearance/axis.m, scripts/plot/appearance/box.m, scripts/plot/appearance/caxis.m, scripts/plot/appearance/clabel.m, scripts/plot/appearance/daspect.m, scripts/plot/appearance/diffuse.m, scripts/plot/appearance/grid.m, scripts/plot/appearance/gtext.m, scripts/plot/appearance/hidden.m, scripts/plot/appearance/legend.m, scripts/plot/appearance/orient.m, scripts/plot/appearance/pbaspect.m, scripts/plot/appearance/private/__axis_label__.m, scripts/plot/appearance/private/__axis_limits__.m, scripts/plot/appearance/shading.m, scripts/plot/appearance/specular.m, scripts/plot/appearance/text.m, scripts/plot/appearance/title.m, scripts/plot/appearance/view.m, scripts/plot/appearance/whitebg.m, scripts/plot/appearance/xlabel.m, scripts/plot/appearance/xlim.m, scripts/plot/appearance/ylabel.m, scripts/plot/appearance/ylim.m, scripts/plot/appearance/zlabel.m, scripts/plot/appearance/zlim.m: Moved from scripts/plot to subdir appearance. * scripts/plot/draw/area.m, scripts/plot/draw/bar.m, scripts/plot/draw/barh.m, scripts/plot/draw/colorbar.m, scripts/plot/draw/comet.m, scripts/plot/draw/comet3.m, scripts/plot/draw/compass.m, scripts/plot/draw/contour.m, scripts/plot/draw/contour3.m, scripts/plot/draw/contourc.m, scripts/plot/draw/contourf.m, scripts/plot/draw/cylinder.m, scripts/plot/draw/ellipsoid.m, scripts/plot/draw/errorbar.m, scripts/plot/draw/ezcontour.m, scripts/plot/draw/ezcontourf.m, scripts/plot/draw/ezmesh.m, scripts/plot/draw/ezmeshc.m, scripts/plot/draw/ezplot.m, scripts/plot/draw/ezplot3.m, scripts/plot/draw/ezpolar.m, scripts/plot/draw/ezsurf.m, scripts/plot/draw/ezsurfc.m, scripts/plot/draw/feather.m, scripts/plot/draw/fill.m, scripts/plot/draw/fplot.m, scripts/plot/draw/hist.m, scripts/plot/draw/isocolors.m, scripts/plot/draw/isonormals.m, scripts/plot/draw/isosurface.m, scripts/plot/draw/line.m, scripts/plot/draw/loglog.m, scripts/plot/draw/loglogerr.m, scripts/plot/draw/mesh.m, scripts/plot/draw/meshc.m, scripts/plot/draw/meshz.m, scripts/plot/draw/pareto.m, scripts/plot/draw/patch.m, scripts/plot/draw/pcolor.m, scripts/plot/draw/peaks.m, scripts/plot/draw/pie.m, scripts/plot/draw/pie3.m, scripts/plot/draw/plot.m, scripts/plot/draw/plot3.m, scripts/plot/draw/plotmatrix.m, scripts/plot/draw/plotyy.m, scripts/plot/draw/polar.m, scripts/plot/draw/private/__add_datasource__.m, scripts/plot/draw/private/__bar__.m, scripts/plot/draw/private/__contour__.m, scripts/plot/draw/private/__errcomm__.m, scripts/plot/draw/private/__errplot__.m, scripts/plot/draw/private/__ezplot__.m, scripts/plot/draw/private/__interp_cube__.m, scripts/plot/draw/private/__line__.m, scripts/plot/draw/private/__marching_cube__.m, scripts/plot/draw/private/__patch__.m, scripts/plot/draw/private/__pie__.m, scripts/plot/draw/private/__plt__.m, scripts/plot/draw/private/__quiver__.m, scripts/plot/draw/private/__scatter__.m, scripts/plot/draw/private/__stem__.m, scripts/plot/draw/quiver.m, scripts/plot/draw/quiver3.m, scripts/plot/draw/rectangle.m, scripts/plot/draw/ribbon.m, scripts/plot/draw/rose.m, scripts/plot/draw/scatter.m, scripts/plot/draw/scatter3.m, scripts/plot/draw/semilogx.m, scripts/plot/draw/semilogxerr.m, scripts/plot/draw/semilogy.m, scripts/plot/draw/semilogyerr.m, scripts/plot/draw/shrinkfaces.m, scripts/plot/draw/slice.m, scripts/plot/draw/sombrero.m, scripts/plot/draw/sphere.m, scripts/plot/draw/stairs.m, scripts/plot/draw/stem.m, scripts/plot/draw/stem3.m, scripts/plot/draw/stemleaf.m, scripts/plot/draw/surf.m, scripts/plot/draw/surface.m, scripts/plot/draw/surfc.m, scripts/plot/draw/surfl.m, scripts/plot/draw/surfnorm.m, scripts/plot/draw/tetramesh.m, scripts/plot/draw/trimesh.m, scripts/plot/draw/triplot.m, scripts/plot/draw/trisurf.m, scripts/plot/draw/waterfall.m: Moved from plot/ to subdir draw. * scripts/plot/util/__actual_axis_position__.m, scripts/plot/util/__default_plot_options__.m, scripts/plot/util/__gnuplot_drawnow__.m, scripts/plot/util/__next_line_color__.m, scripts/plot/util/__next_line_style__.m, scripts/plot/util/__plt_get_axis_arg__.m, scripts/plot/util/__pltopt__.m, scripts/plot/util/allchild.m, scripts/plot/util/ancestor.m, scripts/plot/util/axes.m, scripts/plot/util/cla.m, scripts/plot/util/clf.m, scripts/plot/util/close.m, scripts/plot/util/closereq.m, scripts/plot/util/colstyle.m, scripts/plot/util/copyobj.m, scripts/plot/util/figure.m, scripts/plot/util/findall.m, scripts/plot/util/findfigs.m, scripts/plot/util/findobj.m, scripts/plot/util/gca.m, scripts/plot/util/gcbf.m, scripts/plot/util/gcbo.m, scripts/plot/util/gcf.m, scripts/plot/util/gco.m, scripts/plot/util/ginput.m, scripts/plot/util/gnuplot_binary.in, scripts/plot/util/graphics_toolkit.m, scripts/plot/util/hdl2struct.m, scripts/plot/util/hggroup.m, scripts/plot/util/hold.m, scripts/plot/util/isaxes.m, scripts/plot/util/isfigure.m, scripts/plot/util/ishghandle.m, scripts/plot/util/ishold.m, scripts/plot/util/isprop.m, scripts/plot/util/linkprop.m, scripts/plot/util/meshgrid.m, scripts/plot/util/ndgrid.m, scripts/plot/util/newplot.m, scripts/plot/util/print.m, scripts/plot/util/printd.m, scripts/plot/util/private/__add_default_menu__.m, scripts/plot/util/private/__fltk_ginput__.m, scripts/plot/util/private/__fltk_print__.m, scripts/plot/util/private/__ghostscript__.m, scripts/plot/util/private/__gnuplot_get_var__.m, scripts/plot/util/private/__gnuplot_ginput__.m, scripts/plot/util/private/__gnuplot_has_feature__.m, scripts/plot/util/private/__gnuplot_has_terminal__.m, scripts/plot/util/private/__gnuplot_open_stream__.m, scripts/plot/util/private/__gnuplot_print__.m, scripts/plot/util/private/__gnuplot_version__.m, scripts/plot/util/private/__go_draw_axes__.m, scripts/plot/util/private/__go_draw_figure__.m, scripts/plot/util/private/__print_parse_opts__.m, scripts/plot/util/private/__tight_eps_bbox__.m, scripts/plot/util/refresh.m, scripts/plot/util/refreshdata.m, scripts/plot/util/saveas.m, scripts/plot/util/shg.m, scripts/plot/util/struct2hdl.m, scripts/plot/util/subplot.m: Moved from plot to subdir util. * etc/HACKING: Updated directory structure info. * scripts/Makefile.am, scripts/plot/appearance/module.mk, scripts/plot/draw/module.mk, scripts/plot/util/module.mk: Added new directories to build system.
author Rik <rik@octave.org>
date Fri, 04 Oct 2013 17:09:08 -0700
parents scripts/plot/private/__errplot__.m@76614e624818
children d63878346099
comparison
equal deleted inserted replaced
17571:6e4ea5c8a4bb 17572:7bb76a22cde1
1 ## Copyright (C) 2000-2012 Teemu Ikonen
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {@var{h} =} __errplot__ (@var{fstr}, @var{hax}, @dots{})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 ## Created: 18.7.2000
25 ## Author: Teemu Ikonen <tpikonen@pcu.helsinki.fi>
26 ## Keywords: errorbar, plotting
27
28 function h = __errplot__ (fstr, hax, varargin)
29
30 fmt = __pltopt__ ("__errplot__", fstr);
31
32 ## Set the plot type based on linestyle.
33 switch (fmt.errorstyle)
34 case "~"
35 ifmt = "yerr";
36 case ">"
37 ifmt = "xerr";
38 case "~>"
39 ifmt = "xyerr";
40 case "#"
41 ifmt = "box";
42 case "#~"
43 ifmt = "boxy";
44 case "#~>"
45 ifmt = "boxxy";
46 otherwise
47 ifmt = "yerr";
48 endswitch
49
50 h = [];
51 nplots = columns (varargin{1});
52 for i = 1:nplots
53
54 if (isempty (fmt.color))
55 lc = __next_line_color__ ();
56 else
57 lc = fmt.color ();
58 endif
59 if (isempty (fmt.marker) && isempty (fmt.linestyle))
60 [ls, mk] = __next_line_style__ ();
61 else
62 ls = fmt.linestyle;
63 mk = fmt.marker;
64 endif
65
66 ## Must occur after __next_line_color__ in order to work correctly.
67 hg = hggroup ("parent", hax);
68 h = [h; hg];
69 args = __add_datasource__ ("__errplot__", hg,
70 {"x", "y", "l", "u", "xl", "xu"});
71
72 hl = [(__line__ (hg, "color", lc, "linestyle", ls, "marker", mk)),
73 (__line__ (hg, "color", lc, "linestyle", "-", "marker", "none"))];
74
75 switch (numel (varargin))
76 case 2
77 ydata = varargin{1}(:,i);
78 xdata = 1:numel (ydata);
79 if (strcmp (ifmt, "yerr") || strcmp (ifmt, "boxy"))
80 ldata = varargin{2}(:,i);
81 udata = ldata;
82 xldata = [];
83 xudata = [];
84 elseif (strcmp (ifmt, "xerr") || strcmp (ifmt, "box"))
85 xldata = varargin{2}(:,i);
86 xudata = ldata;
87 ldata = [];
88 udata = [];
89 else
90 error ("errorbar: 2 column errorplot is only valid for xerr or yerr");
91 endif
92 case 3
93 if (strcmp (ifmt, "yerr") || strcmp (ifmt, "boxy"))
94 xdata = varargin{1}(:,i);
95 ydata = varargin{2}(:,i);
96 ldata = varargin{3}(:,i);
97 udata = ldata;
98 xldata = [];
99 xudata = [];
100 elseif (strcmp (ifmt, "xyerr") || strcmp (ifmt, "boxxy"))
101 ydata = varargin{1}(:,i);
102 xdata = 1:numel (ydata);
103 xldata = varargin{2}(:,i);
104 xudata = xldata;
105 ldata = varargin{3}(:,i);
106 udata = ldata;
107 else # xerr or box
108 xdata = varargin{1}(:,i);
109 ydata = varargin{2}(:,i);
110 xldata = varargin{3}(:,i);
111 xudata = xldata;
112 ldata = [];
113 udata = [];
114 endif
115 case 4
116 if (strcmp (ifmt, "yerr") || strcmp (ifmt, "boxy"))
117 xdata = varargin{1}(:,i);
118 ydata = varargin{2}(:,i);
119 ldata = varargin{3}(:,i);
120 udata = varargin{4}(:,i);
121 xldata = [];
122 xudata = [];
123 elseif (strcmp (ifmt, "xyerr") || strcmp (ifmt, "boxxy"))
124 xdata = varargin{1}(:,i);
125 ydata = varargin{2}(:,i);
126 xldata = varargin{3}(:,i);
127 xudata = xldata;
128 ldata = varargin{4}(:,i);
129 udata = ldata;
130 else # xerr or box
131 xdata = varargin{1}(:,i);
132 ydata = varargin{2}(:,i);
133 xldata = varargin{3}(:,i);
134 xudata = varargin{4}(:,i);
135 ldata = [];
136 udata = [];
137 endif
138 case 6 # xyerr, boxxy
139 if (strcmp (ifmt, "xyerr") || strcmp (ifmt, "boxxy"))
140 xdata = varargin{1}(:,i);
141 ydata = varargin{2}(:,i);
142 xldata = varargin{3}(:,i);
143 xudata = varargin{4}(:,i);
144 ldata = varargin{5}(:,i);
145 udata = varargin{6}(:,i);
146 else
147 error ("errorbar: error plot with 6 columns only valid for xyerr and boxxy");
148 endif
149 otherwise
150 error ("errorbar: error plot requires 2, 3, 4, or 6 arguments");
151 endswitch
152
153 addproperty ("xdata", hg, "data", xdata(:));
154 addproperty ("ydata", hg, "data", ydata(:));
155 addproperty ("ldata", hg, "data", ldata(:));
156 addproperty ("udata", hg, "data", udata(:));
157 addproperty ("xldata", hg, "data", xldata(:));
158 addproperty ("xudata", hg, "data", xudata(:));
159 addproperty ("format", hg, "string", ifmt);
160
161 addproperty ("color", hg, "linecolor", get (hl(1), "color"));
162 addproperty ("linestyle", hg, "linelinestyle", get (hl(1), "linestyle"));
163 addproperty ("linewidth", hg, "linelinewidth", get (hl(1), "linewidth"));
164 addproperty ("marker", hg, "linemarker", get (hl(1), "marker"));
165 addproperty ("markeredgecolor", hg, "linemarkerfacecolor",
166 get (hl(1), "markeredgecolor"));
167 addproperty ("markerfacecolor", hg, "linemarkerfacecolor",
168 get (hl(1), "markerfacecolor"));
169 addproperty ("markersize", hg, "linemarkersize",
170 get (hl(1), "markersize"));
171
172 ## Matlab property, although Octave does not implement it.
173 addproperty ("hittestarea", hg, "radio", "on|{off}", "off");
174
175 fcn = {@update_props, hl};
176 addlistener (hg, "color", fcn);
177 addlistener (hg, "linestyle", fcn);
178 addlistener (hg, "linewidth", fcn);
179 addlistener (hg, "marker", fcn);
180 addlistener (hg, "markeredgecolor", fcn);
181 addlistener (hg, "markerfacecolor", fcn);
182 addlistener (hg, "markersize", fcn);
183
184 fcn = {@update_data, hl};
185 addlistener (hg, "xdata", fcn);
186 addlistener (hg, "ydata", fcn);
187 addlistener (hg, "ldata", fcn);
188 addlistener (hg, "udata", fcn);
189 addlistener (hg, "xldata", fcn);
190 addlistener (hg, "xudata", fcn);
191 addlistener (hg, "format", fcn);
192
193 hax = ancestor (hg, "axes");
194 addlistener (hax, "xscale", fcn);
195 addlistener (hax, "yscale", fcn);
196
197 update_data (hg, [], hl);
198
199 endfor
200
201 ## Process legend key
202 if (! isempty (fmt.key))
203 hlegend = [];
204 fkids = get (gcf (), "children");
205 for i = 1 : numel (fkids)
206 if ( strcmp (get (fkids(i), "type"), "axes")
207 && strcmp (get (fkids(i), "tag"), "legend"))
208 udata = get (fkids(i), "userdata");
209 if (! isempty (intersect (udata.handle, gca ())))
210 hlegend = fkids (i);
211 break;
212 endif
213 endif
214 endfor
215
216 if (isempty (hlegend))
217 hlgnd = [];
218 tlgnd = {};
219 else
220 [hlgnd, tlgnd] = __getlegenddata__ (hlegend);
221 endif
222
223 hlgnd(end+1) = hg;
224 tlgnd(end+1) = fmt.key;
225
226 legend (gca (), hlgnd, tlgnd);
227 endif
228
229 endfunction
230
231 function [xdata, ydata] = errorbar_data (xdata, ydata, ldata, udata,
232 xldata, xudata, ifmt,
233 xscale, yscale)
234 if (strcmp (xscale, "linear"))
235 dx = 0.01 * (max (xdata(:)) - min (xdata(:)));
236 xlo = xdata - dx;
237 xhi = xdata + dx;
238 else
239 n = xdata > 0;
240 if (! any (n))
241 n = xdata < 0;
242 endif
243 logdata = log (abs (xdata(n)));
244 rx = exp (0.01 * (max (logdata) - min (logdata)));
245 xlo = xdata/rx;
246 xhi = xdata*rx;
247 endif
248 if (strcmp (yscale, "linear"))
249 dy = 0.01 * (max (ydata(:)) - min (ydata(:)));
250 ylo = ydata - dy;
251 yhi = ydata + dy;
252 else
253 n = ydata > 0;
254 if (! any (n))
255 n = ydata < 0;
256 endif
257 logdata = log (abs (ydata(n)));
258 ry = exp (0.01 * (max (logdata) - min (logdata)));
259 ylo = ydata/ry;
260 yhi = ydata*ry;
261 endif
262 nans = NaN + xdata(:); # fast way to do NaN (size (xdata(:)))
263 if (strcmp (ifmt, "yerr"))
264 xdata = [xdata, xdata, nans, ...
265 xlo, xhi, nans, ...
266 xlo, xhi, nans];
267 ydata = [ydata-ldata, ydata+udata, nans, ...
268 ydata+udata, ydata+udata, nans, ...
269 ydata-ldata, ydata-ldata, nans];
270 elseif (strcmp (ifmt, "xerr"))
271 xdata = [xdata-xldata, xdata+xudata, nans, ...
272 xdata+xudata, xdata+xudata, nans, ...
273 xdata-xldata, xdata-xldata, nans];
274 ydata = [ydata, ydata, nans, ...
275 ylo, yhi, nans, ...
276 ylo, yhi, nans];
277 elseif (strcmp (ifmt, "boxy"))
278 dx = 0.01 * (max (xdata(:)) - min (xdata(:)));
279 xdata = [xlo, xhi, xhi, xlo, xlo, nans];
280 ydata = [ydata-ldata, ydata-ldata, ydata+udata, ydata+udata, ...
281 ydata-ldata, nans];
282 elseif (strcmp (ifmt, "box"))
283 dy = 0.01 * (max (ydata(:)) - min (ydata(:)));
284 xdata = [xdata-xldata, xdata+xudata, xdata+xudata, xdata-xldata, ...
285 xdata-xldata, nans];
286 ydata = [ylo, ylo, yhi, yhi, ylo, nans];
287 elseif (strcmp (ifmt, "boxxy"))
288 xdata = [xdata-xldata, xdata+xudata, xdata+xudata, xdata-xldata, ...
289 xdata-xldata, nans];
290 ydata = [ydata-ldata, ydata-ldata, ydata+udata, ydata+udata, ...
291 ydata-ldata, nans];
292 elseif (strcmp (ifmt, "xyerr"))
293 [x1, y1] = errorbar_data (xdata, ydata, ldata, udata,
294 xldata, xudata, "xerr", xscale, yscale);
295 [x2, y2] = errorbar_data (xdata, ydata, ldata, udata,
296 xldata, xudata, "yerr", xscale, yscale);
297 xdata = [x1; x2];
298 ydata = [y1; y2];
299 return;
300 else
301 error ("errorbar: valid error bar types are xerr, yerr, xyerr, box, boxy, boxxy");
302 endif
303
304 xdata = xdata.'(:);
305 ydata = ydata.'(:);
306
307 endfunction
308
309 function update_props (hg, ~, hl)
310 set (hl, "color", get (hg, "color"),
311 "linewidth", get (hg, "linewidth"));
312 set (hl(1), "linestyle", get (hg, "linestyle"),
313 "marker", get (hg, "marker"),
314 "markeredgecolor", get (hg, "markeredgecolor"),
315 "markerfacecolor", get (hg, "markerfacecolor"),
316 "markersize", get (hg, "markersize"));
317 endfunction
318
319 function update_data (hg, ~, hl)
320
321 if (strcmp (get (hg, "type"), "axes"))
322 hax = hg;
323 hg = ancestor (hl(1), "hggroup");
324 else
325 hax = ancestor (hg, "axes");
326 endif
327 xscale = get (hax, "xscale");
328 yscale = get (hax, "yscale");
329
330 xdata = get (hg, "xdata");
331 ydata = get (hg, "ydata");
332 ldata = get (hg, "ldata");
333 udata = get (hg, "udata");
334 xldata = get (hg, "xldata");
335 xudata = get (hg, "xudata");
336 ifmt = get (hg, "format");
337
338 set (hl(1), "xdata", xdata);
339 set (hl(1), "ydata", ydata);
340
341 [errorbar_xdata, errorbar_ydata] = ...
342 errorbar_data (xdata, ydata, ldata, udata, xldata, xudata, ...
343 ifmt, xscale, yscale);
344
345 set (hl(2), "xdata", errorbar_xdata);
346 set (hl(2), "ydata", errorbar_ydata);
347
348 endfunction
349