Mercurial > hg > octave-nkf
view scripts/plot/private/__errplot__.m @ 14846:460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Example: func() => func ()
* dynamic.txi, func.txi, oop.txi, var.txi, embedded.cc, fortdemo.cc,
funcdemo.cc, paramdemo.cc, stringdemo.cc, unwinddemo.cc, Array.cc, Array.h,
CColVector.cc, CDiagMatrix.h, CMatrix.cc, CNDArray.cc, CRowVector.cc,
CSparse.cc, CmplxGEPBAL.cc, EIG.cc, MSparse.cc, MatrixType.cc,
Sparse-op-defs.h, Sparse-perm-op-defs.h, Sparse.cc, Sparse.h,
SparseCmplxCHOL.cc, SparseCmplxCHOL.h, SparseCmplxLU.cc, SparseCmplxQR.cc,
SparseCmplxQR.h, SparseQR.cc, SparseQR.h, SparsedbleCHOL.cc, SparsedbleCHOL.h,
SparsedbleLU.cc, SparsedbleLU.h, base-lu.cc, cmd-hist.cc, dColVector.cc,
dDiagMatrix.h, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dbleCHOL.cc,
dbleGEPBAL.cc, dim-vector.cc, eigs-base.cc, f2c-main.c, fCColVector.cc,
fCDiagMatrix.h, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fCmplxGEPBAL.cc,
fColVector.cc, fDiagMatrix.h, fEIG.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc,
file-ops.cc, file-stat.cc, floatCHOL.cc, floatGEPBAL.cc, idx-vector.h,
lo-specfun.cc, lo-sysdep.cc, mx-inlines.cc, oct-binmap.h, oct-convn.cc,
oct-md5.cc, oct-mem.h, oct-rand.cc, oct-syscalls.cc, randgamma.c, randmtzig.c,
sparse-base-chol.cc, sparse-base-chol.h, sparse-base-lu.cc, sparse-dmsolve.cc,
tempname.c, curl.m, divergence.m, randi.m, dlmwrite.m, edit.m, getappdata.m,
what.m, getarchdir.m, install.m, installed_packages.m, repackage.m,
unload_packages.m, colorbar.m, figure.m, isosurface.m, legend.m, loglog.m,
plot.m, plot3.m, plotyy.m, polar.m, __errplot__.m, __ghostscript__.m,
__marching_cube__.m, __plt__.m, __scatter__.m, semilogx.m, semilogy.m,
trimesh.m, trisurf.m, demo.m, test.m, datetick.m, __delaunayn__.cc,
__dsearchn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, balance.cc,
bsxfun.cc, ccolamd.cc, cellfun.cc, chol.cc, daspk.cc, dasrt.cc, dassl.cc,
dmperm.cc, eig.cc, eigs.cc, fftw.cc, filter.cc, find.cc, kron.cc, lookup.cc,
lsode.cc, matrix_type.cc, md5sum.cc, mgorth.cc, qr.cc, quad.cc, rand.cc,
regexp.cc, symbfact.cc, tril.cc, urlwrite.cc, op-bm-bm.cc, op-cdm-cdm.cc,
op-cell.cc, op-chm.cc, op-cm-cm.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-scm.cc,
op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-fcdm-fcdm.cc,
op-fcm-fcm.cc, op-fdm-fdm.cc, op-fm-fm.cc, op-int.h, op-m-m.cc, op-m-scm.cc,
op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-scm.cc,
op-s-sm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc,
op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc,
op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-str.cc, op-struct.cc, bitfcns.cc,
data.cc, debug.cc, dynamic-ld.cc, error.cc, gl-render.cc, graphics.cc,
graphics.in.h, load-path.cc, ls-hdf5.cc, ls-mat5.cc, ls-mat5.h,
ls-oct-ascii.cc, ls-oct-ascii.h, mex.cc, mk-errno-list, oct-map.cc, oct-obj.h,
oct-parse.yy, octave-config.in.cc, ov-base-int.cc, ov-base-mat.cc, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-cell.cc, ov-class.cc,
ov-class.h, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-intx.h, ov-range.h, ov-re-mat.cc, ov-re-sparse.cc,
ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.h, ov.h, pr-output.cc, pt-id.cc,
pt-id.h, pt-mat.cc, pt-select.cc, sparse.cc, symtab.cc, symtab.h, syscalls.cc,
toplev.cc, txt-eng-ft.cc, variables.cc, zfstream.cc, zfstream.h, Dork.m,
getStash.m, myStash.m, Gork.m, Pork.m, myStash.m, getStash.m, myStash.m,
getStash.m, myStash.m, fntests.m: Use Octave coding convention for
cuddled parenthis in function calls with empty argument lists.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 08 Jul 2012 11:28:50 -0700 |
parents | 86854d032a37 |
children | 5d3a684236b0 |
line wrap: on
line source
## Copyright (C) 2000-2012 Teemu Ikonen ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn {Function File} {@var{h} =} __errplot__ (@var{fstr}, @var{p}, @dots{}) ## Undocumented internal function. ## @end deftypefn ## Created: 18.7.2000 ## Author: Teemu Ikonen <tpikonen@pcu.helsinki.fi> ## Keywords: errorbar, plotting function h = __errplot__ (fstr, p, varargin) if (nargin < 4 || nargin > 8) # at least two data arguments needed print_usage (); endif [fmt, valid] = __pltopt__ ("__errplot__", fstr); [len, nplots] = size (varargin{1}); h = []; for i = 1:nplots ## Set the plot type based on linestyle. if (strcmp (fmt.errorstyle, "~")) ifmt = "yerr"; elseif (strcmp (fmt.errorstyle, ">")) ifmt = "xerr"; elseif (strcmp (fmt.errorstyle, "~>")) ifmt = "xyerr"; elseif (strcmp (fmt.errorstyle, "#")) ifmt = "box"; elseif (strcmp (fmt.errorstyle, "#~")) ifmt = "boxy"; elseif (strcmp (fmt.errorstyle, "#~>")) ifmt = "boxxy"; else ifmt = "yerr"; endif hg = hggroup ("parent", p); h = [h; hg]; args = __add_datasource__ ("__errplot__", hg, {"x", "y", "l", "u", "xl", "xu"}); if (isempty (fmt.color)) fmt.color = __next_line_color__ (); endif if (isempty (fmt.marker) && isempty (fmt.linestyle)) [fmt.linestyle, fmt.marker] = __next_line_style__ (); endif hl = [(__line__ (hg, "linestyle", fmt.linestyle, "marker", fmt.marker, "color", fmt.color)), (__line__ (hg, "linestyle", "-", "marker", "none", "color", fmt.color))]; switch (numel(varargin)) case 2 ydata = varargin{1}(:,i); xdata = 1:numel (ydata); if (strcmp (ifmt, "xerr") || strcmp (ifmt, "box")) xldata = varargin{2}(:,i); xudata = ldata; ldata = []; udata = []; elseif (strcmp (ifmt, "yerr") || strcmp (ifmt, "boxy")) ldata = varargin{2}(:,i); udata = ldata; xldata = []; xudata = []; else error ("errorbar: 2 column errorplot is only valid for xerr or yerr"); endif case 3 if (strcmp (ifmt, "boxxy") || strcmp (ifmt, "xyerr")) ydata = varargin{1}(:,i); xdata = 1:numel (ydata); xldata = varargin{2}(:,i); xudata = xldata; ldata = varargin{3}(:,i); udata = ldata; elseif (strcmp (ifmt, "xerr") || strcmp (ifmt, "box")) xdata = varargin{1}(:,i); ydata = varargin{2}(:,i); xldata = varargin{3}(:,i); xudata = xldata; ldata = []; udata = []; else # yerr or boxy xdata = varargin{1}(:,i); ydata = varargin{2}(:,i); ldata = varargin{3}(:,i); udata = ldata; xldata = []; xudata = []; endif case 4 if (strcmp (ifmt, "boxxy") || strcmp (ifmt, "xyerr")) xdata = varargin{1}(:,i); ydata = varargin{2}(:,i); xldata = varargin{3}(:,i); xudata = xldata; ldata = varargin{4}(:,i); udata = ldata; elseif (strcmp (ifmt, "xerr") || strcmp (ifmt, "box")) xdata = varargin{1}(:,i); ydata = varargin{2}(:,i); xldata = varargin{3}(:,i); xudata = varargin{4}(:,i); ldata = []; udata = []; else # yerr or boxy xdata = varargin{1}(:,i); ydata = varargin{2}(:,i); ldata = varargin{3}(:,i); udata = varargin{4}(:,i); xldata = []; xudata = []; endif case 6 # boxxy, xyerr if (strcmp (ifmt, "boxxy") || strcmp (ifmt, "xyerr")) xdata = varargin{1}(:,i); ydata = varargin{2}(:,i); xldata = varargin{3}(:,i); xudata = varargin{4}(:,i); ldata = varargin{5}(:,i); udata = varargin{6}(:,i); else error ("errorbar: error plot with 6 columns only valid for boxxy and xyerr"); endif otherwise error ("errorbar: error plot requires 2, 3, 4, or 6 arguments"); endswitch addproperty ("xdata", hg, "data", xdata(:)); addproperty ("ydata", hg, "data", ydata(:)); addproperty ("ldata", hg, "data", ldata(:)); addproperty ("udata", hg, "data", udata(:)); addproperty ("xldata", hg, "data", xldata(:)); addproperty ("xudata", hg, "data", xudata(:)); addproperty ("format", hg, "string", ifmt); addproperty ("color", hg, "linecolor", get (hl(1), "color")); addproperty ("linewidth", hg, "linelinewidth", get (hl(1), "linewidth")); addproperty ("linestyle", hg, "linelinestyle", get (hl(1), "linestyle")); addproperty ("marker", hg, "linemarker", get (hl(1), "marker")); addproperty ("markerfacecolor", hg, "linemarkerfacecolor", get (hl(1), "markerfacecolor")); addproperty ("markeredgecolor", hg, "linemarkerfacecolor", get (hl(1), "markeredgecolor")); addproperty ("markersize", hg, "linemarkersize", get (hl(1), "markersize")); fcn = {@update_props, hl}; addlistener (hg, "color", fcn); addlistener (hg, "linewidth", fcn); addlistener (hg, "linestyle", fcn); addlistener (hg, "marker", fcn); addlistener (hg, "markerfacecolor", fcn); addlistener (hg, "markersize", fcn); fcn = {@update_data, hl}; addlistener (hg, "xdata", fcn); addlistener (hg, "ydata", fcn); addlistener (hg, "ldata", fcn); addlistener (hg, "udata", fcn); addlistener (hg, "xldata", fcn); addlistener (hg, "xudata", fcn); addlistener (hg, "format", fcn); hax = ancestor (hg, "axes"); addlistener (hax, "xscale", fcn); addlistener (hax, "yscale", fcn); update_data (hg, [], hl); endfor ## Process legend key if (! isempty (fmt.key)) hlegend = []; fkids = get (gcf (), "children"); for i = 1 : numel (fkids) if (ishandle (fkids(i)) && strcmp (get (fkids(i), "type"), "axes") && (strcmp (get (fkids(i), "tag"), "legend"))) udata = get (fkids(i), "userdata"); if (! isempty (intersect (udata.handle, gca ()))) hlegend = fkids (i); break; endif endif endfor if (isempty (hlegend)) hlgnd = []; tlgnd = {}; else [hlgnd, tlgnd] = __getlegenddata__ (hlegend); endif hlgnd(end+1) = hg; tlgnd(end+1) = fmt.key; legend (gca (), hlgnd, tlgnd); endif endfunction function [xdata, ydata] = errorbar_data (xdata, ydata, ldata, udata, xldata, xudata, ifmt, xscale, yscale) if (strcmp (xscale, "linear")) dx = 0.01 * (max (xdata(:)) - min (xdata(:))); xlo = xdata - dx; xhi = xdata + dx; else n = xdata > 0; rx = exp(0.01 * (max (log(xdata(n))) - min (log(xdata(n))))); xlo = xdata/rx; xhi = xdata*rx; endif if (strcmp (yscale, "linear")) dy = 0.01 * (max (ydata(:)) - min (ydata(:))); ylo = ydata - dy; yhi = ydata + dy; else n = ydata > 0; ry = exp(0.01 * (max (log(ydata(n))) - min (log(ydata(n))))); ylo = ydata/ry; yhi = ydata*ry; endif nans = NaN + xdata(:); if (strcmp (ifmt, "yerr")) xdata = [xdata, xdata, nans, ... xlo, xhi, nans, ... xlo, xhi, nans]; ydata = [ydata-ldata, ydata+udata, nans, ... ydata+udata, ydata+udata, nans, ... ydata-ldata, ydata-ldata, nans]; elseif (strcmp (ifmt, "xerr")) xdata = [xdata-xldata, xdata+xudata, nans, ... xdata+xudata, xdata+xudata, nans, ... xdata-xldata, xdata-xldata, nans]; ydata = [ydata, ydata, nans, ... ylo, yhi, nans, ... ylo, yhi, nans]; elseif (strcmp (ifmt, "boxy")) dx = 0.01 * (max (xdata(:)) - min (xdata(:))); xdata = [xlo, xhi, xhi, xlo, xlo, nans]; ydata = [ydata-ldata, ydata-ldata, ydata+udata, ydata+udata, ... ydata-ldata, nans]; elseif (strcmp (ifmt, "box")) dy = 0.01 * (max (ydata(:)) - min (ydata(:))); xdata = [xdata-xldata, xdata+xudata, xdata+xudata, xdata-xldata, ... xdata-xldata, nans]; ydata = [ylo, ylo, yhi, yhi, ylo, nans]; elseif (strcmp (ifmt, "boxxy")) xdata = [xdata-xldata, xdata+xudata, xdata+xudata, xdata-xldata, ... xdata-xldata, nans]; ydata = [ydata-ldata, ydata-ldata, ydata+udata, ydata+udata, ... ydata-ldata, nans]; elseif (strcmp (ifmt, "xyerr")) [x1, y1] = errorbar_data (xdata, ydata, ldata, udata, xldata, xudata, "xerr", xscale, yscale); [x2, y2] = errorbar_data (xdata, ydata, ldata, udata, xldata, xudata, "yerr", xscale, yscale); xdata = [x1; x2]; ydata = [y1; y2]; return else error ("errorbar: valid error bar types are xerr, yerr, boxxy, and xyerr"); endif xdata = xdata.'(:); ydata = ydata.'(:); endfunction function update_props (hg, dummy, hl) set (hl, "color", get (hg, "color"), "linewidth", get (hg, "linewidth"));, set (hl(1), "linestyle", get (hg, "linestyle"), "marker", get (hg, "marker"), "markersize", get (hg, "markersize"), "markerfacecolor", get (hg, "markerfacecolor"), "markeredgecolor", get (hg, "markeredgecolor")); endfunction function update_data (hg, dummy, hl) if (strcmp (get (hg, "type"), "axes")) hax = hg; hg = ancestor (hl(1), "hggroup"); else hax = ancestor (hg, "axes"); endif xscale = get (hax, "xscale"); yscale = get (hax, "yscale"); xdata = get (hg, "xdata"); ydata = get (hg, "ydata"); ldata = get (hg, "ldata"); udata = get (hg, "udata"); xldata = get (hg, "xldata"); xudata = get (hg, "xudata"); ifmt = get (hg, "format"); set (hl(1), "xdata", xdata); set (hl(1), "ydata", ydata); [errorbar_xdata, errorbar_ydata] = ... errorbar_data (xdata, ydata, ldata, udata, xldata, xudata, ... ifmt, xscale, yscale); set (hl(2), "xdata", errorbar_xdata); set (hl(2), "ydata", errorbar_ydata); endfunction