annotate scripts/plot/draw/private/__bar__.m @ 30893:e1788b1a315f

maint: Use "fcn" as preferred abbreviation for "function" in m-files. * accumarray.m, accumdim.m, quadl.m, quadv.m, randi.m, structfun.m, __is_function__.m, uigetfile.m, uimenu.m, uiputfile.m, doc_cache_create.m, colorspace_conversion_input_check.m, imageIO.m, argnames.m, vectorize.m, vectorize.m, normest1.m, inputname.m, nthargout.m, display_info_file.m, decic.m, ode15i.m, ode15s.m, ode23.m, ode23s.m, ode45.m, odeset.m, check_default_input.m, integrate_adaptive.m, ode_event_handler.m, runge_kutta_23.m, runge_kutta_23s.m, runge_kutta_45_dorpri.m, runge_kutta_interpolate.m, starting_stepsize.m, __all_opts__.m, fminbnd.m, fminsearch.m, fminunc.m, fsolve.m, fzero.m, sqp.m, fplot.m, plotyy.m, __bar__.m, __ezplot__.m, flat_entry.html, profexport.m, movfun.m, bicg.m, bicgstab.m, cgs.m, eigs.m, gmres.m, pcg.m, __alltohandles__.m, __sprand__.m, qmr.m, tfqmr.m, dump_demos.m: Replace "func", "fun", "fn" in documentation and variable names with "fcn".
author Rik <rik@octave.org>
date Mon, 04 Apr 2022 18:14:56 -0700
parents 796f54d4ddbf
children 505ed551e366
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30379
diff changeset
3 ## Copyright (C) 1996-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27898
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
7 ##
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24145
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24145
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22488
diff changeset
13 ## (at your option) any later version.
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
14 ##
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22488
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22488
diff changeset
18 ## GNU General Public License for more details.
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
19 ##
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24145
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
25
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8664
diff changeset
26 ## -*- texinfo -*-
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
27 ## @deftypefn {} {} __bar__ (@var{vertical}, @var{fcn}, @dots{})
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6886
diff changeset
28 ## Undocumented internal function.
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8664
diff changeset
29 ## @end deftypefn
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
30
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
31 function varargout = __bar__ (fcn, vertical, varargin)
6886
1c1d62569590 [project @ 2007-09-10 20:58:34 by jwe]
jwe
parents: 6885
diff changeset
32
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
33 [hax, varargin, nargin] = __plt_get_axis_arg__ (fcn, varargin{:});
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7148
diff changeset
34
24145
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
35 if (! isnumeric (varargin{1}))
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
36 error ("%s: Y must be numeric", fcn);
24145
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
37 endif
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
38
22488
a666e3ee6af8 Require gnuplot 4.4 as mininimum supported version.
Rik <rik@octave.org>
parents: 22367
diff changeset
39 width = 0.8;
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
40 group = true;
29071
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
41 stacked = false;
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
42 histc = NA;
22930
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
43 ## BaseValue
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
44 if (strcmp (get (hax, "yscale"), "log"))
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
45 bv = 1;
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
46 else
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
47 bv = 0;
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
48 endif
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
49
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
50 if (nargin > 1 && isnumeric (varargin{2}))
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
51 x = varargin{1};
6886
1c1d62569590 [project @ 2007-09-10 20:58:34 by jwe]
jwe
parents: 6885
diff changeset
52 if (isvector (x))
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
53 x = x(:);
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
54 endif
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
55 y = varargin{2};
6886
1c1d62569590 [project @ 2007-09-10 20:58:34 by jwe]
jwe
parents: 6885
diff changeset
56 if (isvector (y))
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
57 y = y(:);
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
58 endif
24145
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
59 if (isscalar (y) && ! isscalar (x))
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
60 ## "y" is actually "width" argument
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
61 y = x;
14872
c2dbdeaa25df maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents: 14868
diff changeset
62 x = [1:rows(y)]';
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
63 idx = 2;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
64 else
6886
1c1d62569590 [project @ 2007-09-10 20:58:34 by jwe]
jwe
parents: 6885
diff changeset
65 if (! isvector (x))
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
66 error ("%s: X must be a vector", fcn);
24145
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
67 elseif (numel (unique (x)) != numel (x))
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
68 error ("%s: X vector values must be unique", fcn);
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
69 endif
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
70 idx = 3;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
71 endif
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
72 else
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
73 y = varargin{1};
6886
1c1d62569590 [project @ 2007-09-10 20:58:34 by jwe]
jwe
parents: 6885
diff changeset
74 if (isvector (y))
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
75 y = y(:);
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
76 endif
14872
c2dbdeaa25df maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents: 14868
diff changeset
77 x = [1:rows(y)]';
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
78 idx = 2;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
79 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
80
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
81 newargs = {};
6886
1c1d62569590 [project @ 2007-09-10 20:58:34 by jwe]
jwe
parents: 6885
diff changeset
82 have_line_spec = false;
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
83 while (idx <= nargin)
8190
73d6b71788c0 use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents: 8056
diff changeset
84 if (ischar (varargin{idx}) && strcmpi (varargin{idx}, "grouped"))
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
85 group = true;
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 19697
diff changeset
86 idx += 1;
8190
73d6b71788c0 use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents: 8056
diff changeset
87 elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "stacked"))
29071
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
88 stacked = true;
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
89 group = false;
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 19697
diff changeset
90 idx += 1;
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
91 elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "histc"))
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
92 group = true;
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19284
diff changeset
93 histc = true;
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 19697
diff changeset
94 idx += 1;
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
95 elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "hist"))
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
96 group = true;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
97 histc = false;
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 19697
diff changeset
98 idx += 1;
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
99 else
17462
177147bf7b55 Overhaul use of __pltopt__.m to correctly check for cellstr, not just cell.
Rik <rik@octave.org>
parents: 17301
diff changeset
100 if ((ischar (varargin{idx}) || iscellstr (varargin{idx}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
101 && ! have_line_spec)
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
102 [linespec, valid] = __pltopt__ (fcn, varargin{idx}, false);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
103 if (valid)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
104 have_line_spec = true;
14388
b5b49f400f9b __bar__.m: Add missing semicolon to stop internal results being printed.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
105 ## FIXME: strange parse error requires semicolon to be spaced
b5b49f400f9b __bar__.m: Add missing semicolon to stop internal results being printed.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
106 ## away from closing ']' on next line.
b5b49f400f9b __bar__.m: Add missing semicolon to stop internal results being printed.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
107 newargs = [{"facecolor", linespec.color}, newargs] ;
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 19697
diff changeset
108 idx += 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
109 continue;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
110 endif
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
111 endif
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14388
diff changeset
112 if (isscalar (varargin{idx}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
113 width = varargin{idx++};
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
114 elseif (idx == nargin)
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
115 newargs = [newargs, varargin(idx++)];
8190
73d6b71788c0 use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents: 8056
diff changeset
116 elseif (ischar (varargin{idx})
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
117 && strcmpi (varargin{idx}, "basevalue")
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
118 && isscalar (varargin{idx+1}))
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents: 7215
diff changeset
119 bv = varargin{idx+1};
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents: 7215
diff changeset
120 idx += 2;
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
121 else
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
122 newargs = [newargs, varargin(idx:idx+1)];
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
123 idx += 2;
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
124 endif
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
125 endif
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
126 endwhile
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
127
29139
f5e89a80ba8c Use colors from "colormap" property for bar, barh if a "hist" option was given (bug #59589).
Rik <rik@octave.org>
parents: 29130
diff changeset
128 ishist = islogical (histc);
f5e89a80ba8c Use colors from "colormap" property for bar, barh if a "hist" option was given (bug #59589).
Rik <rik@octave.org>
parents: 29130
diff changeset
129
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
130 ngrp = rows (x);
24145
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
131
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
132 if (isvector (y) && ngrp != rows (y))
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
133 y = y.';
196ea1ee99b8 Revamp input validation for bar functions (bug #52135).
Rik <rik@octave.org>
parents: 23947
diff changeset
134 endif
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
135 if (ngrp != rows (y))
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
136 error ("%s: length of X and Y must be equal", fcn);
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
137 endif
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
138
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
139 nbars = columns (y);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
140
18776
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
141 ## Column width is 1 for 'hist*' styles (bars touch).
29139
f5e89a80ba8c Use colors from "colormap" property for bar, barh if a "hist" option was given (bug #59589).
Rik <rik@octave.org>
parents: 29130
diff changeset
142 if (ishist)
18776
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
143 cwidth = 1;
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
144 if (nbars == 1)
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
145 gwidth = 1;
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
146 else
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
147 gwidth = width^2;
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
148 endif
d99475e26c78 Fix regression in width of bars for hist() (bug #42401).
Rik <rik@octave.org>
parents: 17744
diff changeset
149 elseif (nbars == 1)
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
150 cwidth = 1;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
151 gwidth = width;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
152 else
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
153 cwidth = gwidth = width;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
154 endif
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
155
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
156 ## Complicated algorithm sizes bars with unitless parameter width.
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
157 ## If width is 1.0, adjacent bars in a group are touching.
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
158 ## Otherwise, bar size is cwidth and the remaining space is split evenly on
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
159 ## either side of the bar. For the default 0.8, spacing is [0.1 0.8 0.1].
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
160 ## Groups of bars are spaced by gwidth. If gwidth is 1.0 then adjacent
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
161 ## groups will just touch.
11202
1840a0ecf1fb __bar__.m: Permit bar() to be called with scalar inputs.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
162 if (numel (x) > 1)
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14388
diff changeset
163 cutoff = min (diff (double (x))) / 2;
11202
1840a0ecf1fb __bar__.m: Permit bar() to be called with scalar inputs.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
164 else
1840a0ecf1fb __bar__.m: Permit bar() to be called with scalar inputs.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
165 cutoff = 1;
1840a0ecf1fb __bar__.m: Permit bar() to be called with scalar inputs.
Ben Abbott <bpabbott@mac.com>
parents: 10549
diff changeset
166 endif
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
167 if (group)
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19284
diff changeset
168 gdelta = cutoff * gwidth / nbars;
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
169 cdelta = repmat ((1 - ((1 - cwidth) / 2)) * gdelta, size (x));
8056
9a6f4713f765 Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents: 7768
diff changeset
170 else
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
171 cdelta = repmat (cutoff * gwidth, size (x));
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
172 endif
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
173 x1 = (x - cdelta)(:)';
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
174 x2 = (x + cdelta)(:)';
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
175 xb = repmat ([x1; x1; x2; x2](:), 1, nbars);
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
176
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
177 if (group)
29139
f5e89a80ba8c Use colors from "colormap" property for bar, barh if a "hist" option was given (bug #59589).
Rik <rik@octave.org>
parents: 29130
diff changeset
178 if (ishist && histc)
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
179 offset = 2*cdelta * [0:(nbars-1)] + cdelta(1); # not centered
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
180 else
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
181 offset = 2*cdelta * [-(nbars - 1) / 2 : (nbars - 1) / 2];
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
182 endif
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
183
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
184 xb(1:4:4*ngrp,:) += offset + (1-cwidth) / 2 * (2 * gdelta);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
185 xb(2:4:4*ngrp,:) += offset + (1-cwidth) / 2 * (2 * gdelta);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
186 xb(3:4:4*ngrp,:) += offset - (1-cwidth) / 2 * (2 * gdelta);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
187 xb(4:4:4*ngrp,:) += offset - (1-cwidth) / 2 * (2 * gdelta);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
188
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents: 7215
diff changeset
189 y0 = zeros (size (y)) + bv;
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
190 y1 = y;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
191 else
29071
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
192 if (stacked && any (y(:) < 0))
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
193 ypos = (y >= 0);
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
194 yneg = (y < 0);
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
195
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
196 y1p = cumsum (y .* ypos, 2);
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
197 y1n = cumsum (y .* yneg, 2);
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
198 y1 = y1p .* ypos + y1n .* yneg;
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
199
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
200 y0p = [zeros(ngrp,1)+bv, y1p(:,1:end-1)];
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
201 y0n = [zeros(ngrp,1)+bv, y1n(:,1:end-1)];
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
202 y0 = y0p .* ypos + y0n .* yneg;
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
203
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
204 else
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
205 y1 = cumsum (y,2);
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
206 y0 = [zeros(ngrp,1)+bv, y1(:,1:end-1)];
d2f7fb06bce3 Fixed stacked bar chart handling of negative values (bug #58216)
Nicholas R. Jankowski <jankowskin@asme.org>
parents: 27923
diff changeset
207 endif
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
208 endif
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
209
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
210 yb = zeros (4*ngrp, nbars);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
211 yb(1:4:4*ngrp,:) = y0;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
212 yb(2:4:4*ngrp,:) = y1;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
213 yb(3:4:4*ngrp,:) = y1;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
214 yb(4:4:4*ngrp,:) = y0;
6885
987a7bf45c99 [project @ 2007-09-10 20:51:09 by jwe]
jwe
parents: 6633
diff changeset
215
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
216 xb = reshape (xb, [4, ngrp, nbars]);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
217 yb = reshape (yb, [4, ngrp, nbars]);
6885
987a7bf45c99 [project @ 2007-09-10 20:51:09 by jwe]
jwe
parents: 6633
diff changeset
218
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7148
diff changeset
219 if (nargout < 2)
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
220 oldfig = [];
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
221 if (! isempty (hax))
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
222 oldfig = get (0, "currentfigure");
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
223 endif
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
224 unwind_protect
17058
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
225 hax = newplot (hax);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
226
29146
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
227 htmp = bars (hax, ishist, vertical, x, y, xb, yb, gwidth, group,
17058
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
228 have_line_spec, bv, newargs{:});
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
229
22367
459545bc9019 Use ishold () rather than ishold (hax) for performance.
Rik <rik@octave.org>
parents: 22366
diff changeset
230 if (! ishold ())
23947
d837f7f6e4aa Don't label all values on bar plot when there are more than 15 bars (bug #51773).
Rik <rik@octave.org>
parents: 23220
diff changeset
231 if (numel (x(:,1)) <= 15 && all (x(:,1) == fix (x(:,1))))
d837f7f6e4aa Don't label all values on bar plot when there are more than 15 bars (bug #51773).
Rik <rik@octave.org>
parents: 23220
diff changeset
232 ## Set manual ticks, rather than relying on autoselection,
d837f7f6e4aa Don't label all values on bar plot when there are more than 15 bars (bug #51773).
Rik <rik@octave.org>
parents: 23220
diff changeset
233 ## when ticks are a small number of integers.
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
234 if (vertical)
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
235 set (hax, "xtick", x(:,1));
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
236 else
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
237 set (hax, "ytick", x(:,1));
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
238 endif
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
239 endif
29146
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
240 if (ishist)
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
241 set (hax, "climmode", "auto");
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
242 else
29146
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
243 ## Hack prevents xlim setting changes when basevalue changes.
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
244 if (vertical)
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
245 set (hax, "xlimmode", "manual");
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
246 else
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
247 set (hax, "ylimmode", "manual");
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
248 endif
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
249 endif
26548
58ad6355ece8 Enable axes ticks on top of bars of bar plots for Matlab compatiblity (bug #55481).
Rik <rik@octave.org>
parents: 26376
diff changeset
250 set (hax, "box", "on", "layer", "top");
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
251 endif
17058
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
252 unwind_protect_cleanup
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
253 if (! isempty (oldfig))
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
254 set (0, "currentfigure", oldfig);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
255 endif
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
256 end_unwind_protect
17058
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
257 if (nargout == 1)
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
258 varargout{1} = htmp;
95c6cada5067 __bar__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 17032
diff changeset
259 endif
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7148
diff changeset
260 else
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7148
diff changeset
261 if (vertical)
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
262 varargout{1} = xb;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
263 varargout{2} = yb;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
264 else
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
265 varargout{1} = yb;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
266 varargout{2} = xb;
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
267 endif
6886
1c1d62569590 [project @ 2007-09-10 20:58:34 by jwe]
jwe
parents: 6885
diff changeset
268 endif
7191
b48a21816f2e [project @ 2007-11-26 21:24:32 by jwe]
jwe
parents: 7189
diff changeset
269
6540
9dcfc78da664 [project @ 2007-04-18 21:16:08 by dbateman]
dbateman
parents:
diff changeset
270 endfunction
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
271
29146
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
272 function hglist = bars (hax, ishist, vertical, x, y, xb, yb, width, group, have_color_spec, base_value, varargin)
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
273
29146
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
274 hglist = [];
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
275 nbars = columns (y);
29146
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
276
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
277 if (ishist)
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
278 ## Special case for Matlab compatibility. For 'hist', 'histc' arguments,
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
279 ## return Patch objects rather than hggroup Bar object.
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
280 for i = 1:nbars
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
281
29146
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
282 if (vertical)
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
283 h = patch (hax, xb(:,:,i), yb(:,:,i),
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
284 "cdata", i*ones (columns (xb),1), "FaceColor", "flat");
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
285 else
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
286 h = patch (hax, yb(:,:,i), xb(:,:,i),
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
287 "cdata", i*ones (columns (yb),1), "FaceColor", "flat");
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
288 endif
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
289
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
290 if (! isempty (varargin))
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
291 set (h, varargin{:});
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
292 endif
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
293
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
294 hglist = [hglist; h];
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
295 endfor
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
296
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
297 return; # return immediately, rest of function is for creating Bar object.
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
298 endif
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
299
3000414c60eb Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
Rik <rik@octave.org>
parents: 29139
diff changeset
300 ## Code to create hggroup Bar object
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
301 for i = 1:nbars
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
302 hg = hggroup ();
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
303 hglist = [hglist; hg];
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
304 args = __add_datasource__ ("bar", hg, {"x", "y"}, varargin{:});
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
305
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
306 if (vertical)
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
307 if (! have_color_spec)
29130
8bb14f4979ca Use colors from axes' "ColorOrder" property for bar charts for Matlab compatibility (bug #59589).
Rik <rik@octave.org>
parents: 29072
diff changeset
308 color = __next_line_color__ ();
8bb14f4979ca Use colors from axes' "ColorOrder" property for bar charts for Matlab compatibility (bug #59589).
Rik <rik@octave.org>
parents: 29072
diff changeset
309 h = patch (hax, xb(:,:,i), yb(:,:,i), "FaceColor", color, "parent", hg);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
310 else
29139
f5e89a80ba8c Use colors from "colormap" property for bar, barh if a "hist" option was given (bug #59589).
Rik <rik@octave.org>
parents: 29130
diff changeset
311 h = patch (hax, xb(:,:,i), yb(:,:,i), "cdata", i, "parent", hg);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
312 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
313 else
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
314 if (! have_color_spec)
29130
8bb14f4979ca Use colors from axes' "ColorOrder" property for bar charts for Matlab compatibility (bug #59589).
Rik <rik@octave.org>
parents: 29072
diff changeset
315 color = __next_line_color__ ();
8bb14f4979ca Use colors from axes' "ColorOrder" property for bar charts for Matlab compatibility (bug #59589).
Rik <rik@octave.org>
parents: 29072
diff changeset
316 h = patch (hax, yb(:,:,i), xb(:,:,i), "FaceColor", color, "parent", hg);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
317 else
29139
f5e89a80ba8c Use colors from "colormap" property for bar, barh if a "hist" option was given (bug #59589).
Rik <rik@octave.org>
parents: 29130
diff changeset
318 h = patch (hax, yb(:,:,i), xb(:,:,i), "cdata", i, "parent", hg);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
319 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
320 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
321
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
322 if (i == 1)
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
323 ## Add baseline object the first time through loop
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
324 x_axis_range = get (hax, "xlim");
26217
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 25054
diff changeset
325 h_baseline = __go_line__ (hax, "xdata", x_axis_range,
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 25054
diff changeset
326 "ydata", [base_value, base_value],
31267a10f8a9 Use __go_line__ directly in plot scripts for performance.
Rik <rik@octave.org>
parents: 25054
diff changeset
327 "color", [0, 0, 0]);
27106
6bfd3a890185 Consolidate separate calls to set() in to one call for interpreter efficiency.
Rik <rik@octave.org>
parents: 26548
diff changeset
328 set (h_baseline, "handlevisibility", "off", "xliminclude", "off",
6bfd3a890185 Consolidate separate calls to set() in to one call for interpreter efficiency.
Rik <rik@octave.org>
parents: 26548
diff changeset
329 "parent", get (hg, "parent"));
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
330 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
331
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
332 ## Setup the hggroup and listeners
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
333 addproperty ("showbaseline", hg, "radio", "{on}|off");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
334 addproperty ("basevalue", hg, "data", base_value);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
335 addproperty ("baseline", hg, "data", h_baseline);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
336
15484
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
337 addlistener (hg, "showbaseline", {@show_baseline, "showbl"});
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
338 addlistener (hg, "visible", {@show_baseline, "visib"});
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
339 addlistener (hg, "basevalue", @move_baseline);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
340
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
341 addproperty ("barwidth", hg, "data", width);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
342 if (group)
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
343 addproperty ("barlayout", hg, "radio", "stacked|{grouped}", "grouped");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
344 else
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
345 addproperty ("barlayout", hg, "radio", "{stacked}|grouped", "stacked");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
346 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
347 if (vertical)
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
348 addproperty ("horizontal", hg, "radio", "on|{off}", "off");
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
349 else
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
350 addproperty ("horizontal", hg, "radio", "{on}|off", "on");
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
351 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
352
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
353 addlistener (hg, "barwidth", @update_group);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
354 addlistener (hg, "barlayout", @update_group);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
355 addlistener (hg, "horizontal", @update_group);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
356
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
357 addproperty ("edgecolor", hg, "patchedgecolor", get (h, "edgecolor"));
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
358 addproperty ("facecolor", hg, "patchfacecolor", get (h, "facecolor"));
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
359 addproperty ("linestyle", hg, "patchlinestyle", get (h, "linestyle"));
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
360 addproperty ("linewidth", hg, "patchlinewidth", get (h, "linewidth"));
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
361
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
362 addlistener (hg, "edgecolor", @update_props);
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
363 addlistener (hg, "facecolor", @update_props);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
364 addlistener (hg, "linestyle", @update_props);
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
365 addlistener (hg, "linewidth", @update_props);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
366
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
367 if (isvector (x))
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
368 addproperty ("xdata", hg, "data", x);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
369 else
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
370 addproperty ("xdata", hg, "data", x(:, i));
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
371 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
372 addproperty ("ydata", hg, "data", y(:, i));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
373
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
374 addlistener (hg, "xdata", @update_data);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
375 addlistener (hg, "ydata", @update_data);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
376
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
377 addproperty ("bargroup", hg, "data");
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
378 set (hglist, "bargroup", hglist);
17527
76614e624818 Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents: 17519
diff changeset
379
76614e624818 Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents: 17519
diff changeset
380 ## Matlab property, although Octave does not implement it.
76614e624818 Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents: 17519
diff changeset
381 addproperty ("hittestarea", hg, "radio", "on|{off}", "off");
76614e624818 Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents: 17519
diff changeset
382
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
383 if (! isempty (args))
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
384 set (hg, args{:});
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
385 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
386 endfor
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
387
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
388 update_xlim (hax, []);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
389 ## Add listeners outside of for loop to prevent constant updating during
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
390 ## creation of plot when patch objects are added.
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
391 addlistener (hax, "xlim", @update_xlim);
22930
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
392 addlistener (hax, "yscale", {@update_basevalue_logscale, hg});
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
393 addlistener (h_baseline, "ydata", @update_baseline);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
394 addlistener (h_baseline, "visible", @update_baseline);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
395
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
396 endfunction
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
397
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
398 function update_xlim (h, ~)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
399
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
400 kids = get (h, "children");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
401 xlim = get (h, "xlim");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
402
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
403 for i = 1 : length (kids)
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
404 obj = get (kids(i));
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
405 if (strcmp (obj.type, "hggroup") && isfield (obj, "baseline"))
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
406 if (any (get (obj.baseline, "xdata") != xlim))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
407 set (obj.baseline, "xdata", xlim);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
408 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
409 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
410 endfor
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
411
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
412 endfunction
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
413
22930
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
414 function update_basevalue_logscale (hax, ~, hg)
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29359
diff changeset
415
22930
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
416 if (strcmp (get (hax, "yscale"), "log"))
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
417 warning ("off", "Octave:negative-data-log-axis", "local");
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
418 if (get (hg, "basevalue") == 0)
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
419 set (hg, "basevalue", 1);
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
420 endif
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
421 else
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
422 if (get (hg, "basevalue") == 1)
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
423 set (hg, "basevalue", 0);
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
424 endif
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
425 endif
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29359
diff changeset
426
22930
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
427 endfunction
f2d2edab5c66 Change basevalue of bar charts when axes scale changed to log (bug #41944).
Rik <rik@octave.org>
parents: 22755
diff changeset
428
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
429 function update_baseline (h, ~)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
430
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
431 visible = get (h, "visible");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
432 ydata = get (h, "ydata")(1);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
433
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
434 ## Search axis for a bargroup that contains this baseline handle
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
435 kids = get (get (h, "parent"), "children");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
436 for i = 1 : length (kids)
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
437 obj = get (kids(i));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
438 if (strcmp (obj.type, "hggroup") && isfield (obj, "baseline")
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
439 && obj.baseline == h)
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
440 set (obj.bargroup, "showbaseline", visible, "basevalue", ydata);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
441 break;
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
442 endif
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
443 endfor
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
444
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
445 endfunction
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
446
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
447 function show_baseline (h, ~, prop = "")
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
448 persistent recursion = false;
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19284
diff changeset
449
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
450 ## Don't allow recursion
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
451 if (! recursion)
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
452 unwind_protect
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
453 recursion = true;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
454 hlist = get (h, "bargroup");
15484
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
455 if (strcmp (prop, "showbl"))
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
456 showbaseline = get (h, "showbaseline");
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
457 hlist = hlist(hlist != h); # remove current handle being updated
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
458 set (hlist, "showbaseline", showbaseline);
15484
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
459 elseif (strcmp (prop, "visib"))
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
460 showbaseline = "on";
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
461 if (all (strcmp (get (hlist, "visible"), "off")))
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
462 showbaseline = "off";
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
463 endif
15484
0133339a51c3 hide baseline when bar group is made invisible
Pantxo <pantxo.diribarne@gmail.com>
parents: 15483
diff changeset
464 endif
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
465 set (get (h, "baseline"), "visible", showbaseline);
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
466 unwind_protect_cleanup
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
467 recursion = false;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
468 end_unwind_protect
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
469 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
470
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
471 endfunction
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
472
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
473 function move_baseline (h, ~)
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
474 persistent recursion = false;
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
475
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
476 ## Don't allow recursion
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
477 if (! recursion)
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
478 recursion = true;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
479 unwind_protect
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
480 b0 = get (h, "basevalue");
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
481 bl = get (h, "baseline");
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
482 set (bl, "ydata", [b0, b0]);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
483
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
484 if (strcmp (get (h, "barlayout"), "grouped"))
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
485 update_data (h);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
486 endif
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
487 unwind_protect_cleanup
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
488 recursion = false;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
489 end_unwind_protect
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
490 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
491
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
492 endfunction
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
493
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
494 function update_props (h, ~)
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
495 kids = get (h, "children");
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
496 set (kids, {"edgecolor", "linewidth", "linestyle", "facecolor"},
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
497 get (h, {"edgecolor", "linewidth", "linestyle", "facecolor"}));
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
498 endfunction
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
499
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
500 function update_data (h, ~)
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
501 persistent recursion = false;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
502
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
503 ## Don't allow recursion
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
504 if (! recursion)
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
505 unwind_protect
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
506 recursion = true;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
507 hlist = get (h, "bargroup");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
508 x = get (h, "xdata");
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
509 if (! isvector (x))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
510 x = x(:);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
511 endif
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
512 ydat = get (hlist, "ydata");
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
513 if (iscell (ydat))
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
514 y = cell2mat (ydat.');
19284
f96495e88a70 Allow setting horizontal vector of "ydata" in bar plots (bug #43468).
Rik <rik@octave.org>
parents: 18776
diff changeset
515 elseif (isvector (ydat))
f96495e88a70 Allow setting horizontal vector of "ydata" in bar plots (bug #43468).
Rik <rik@octave.org>
parents: 18776
diff changeset
516 y = ydat(:);
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
517 else
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
518 y = ydat;
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
519 endif
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
520
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
521 [xb, yb] = bar (x, y, get (h, "barwidth"), get (h, "barlayout"),
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
522 "basevalue", get (h, "basevalue"));
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
523
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
524 vertical = strcmp (get (h, "horizontal"), "off");
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
525 for i = 1:columns (y)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
526 hp = get (hlist(i), "children");
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
527 if (vertical)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
528 set (hp, "xdata", xb(:,:,i), "ydata", yb(:,:,i));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
529 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
530 set (hp, "xdata", yb(:,:,i), "ydata", xb(:,:,i));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
531 endif
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
532 endfor
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
533 unwind_protect_cleanup
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
534 recursion = false;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
535 end_unwind_protect
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
536 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
537
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
538 endfunction
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
539
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
540 function update_group (h, ~)
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
541 persistent recursion = false;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
542
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
543 ## Don't allow recursion
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
544 if (! recursion)
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
545 unwind_protect
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
546 recursion = true;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
547 hlist = get (h, "bargroup");
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14388
diff changeset
548 barwidth = get (h, "barwidth");
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
549 barlayout = get (h, "barlayout");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
550 horizontal = get (h, "horizontal");
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
551
17519
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
552 hlist = hlist(hlist != h); # remove current handle being updated
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
553 set (hlist, "barwidth", barwidth, "barlayout", barlayout,
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
554 "horizontal", horizontal);
cc9befe5d271 Overhaul bar family of plot functions.
Rik <rik@octave.org>
parents: 17462
diff changeset
555 update_data (h);
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
556 unwind_protect_cleanup
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
557 recursion = false;
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
558 end_unwind_protect
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
559 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
560
9896
1aeb39118764 convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
561 endfunction