0
|
1 ## Copyright (C) 1999 Daniel Heiserer |
|
2 ## |
|
3 ## This program is free software. It is distributed in the hope that it |
|
4 ## will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
5 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
|
6 ## the GNU General Public License for more details. |
|
7 ## |
|
8 ## You should have received a copy of the GNU General Public License |
|
9 ## along with this file; see the file COPYING. If not, write to the |
|
10 ## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
11 ## 02111-1307, USA. |
|
12 |
|
13 ## BAR create Bar graph |
|
14 ## USAGE: |
|
15 ## BAR(X) creates a bar plot using the colums of the m x n Matrix X |
|
16 ## as columns of the bars. The rows of X will |
|
17 ## |
|
18 ## BAR(...,'stack') creates a vertical bar chart. |
|
19 ## BAR(...,'group') creates a horizontal bar chart. |
|
20 ## |
|
21 ## |
|
22 ## e.g.: bar(rand(3,5),'stack') |
|
23 ## |
|
24 ## See also FILL, PATCH. |
|
25 |
|
26 ## REMARK: fakes gnuplots unability of plotting shaded patches |
|
27 ## AUTHOR: Daniel Heiserer <Daniel.heiserer@physik.tu-muenchen.de> |
|
28 ## 2001-01-16 Paul Kienzle |
|
29 ## * reformatting, unwind protect, compatible style names |
|
30 |
|
31 function dhbar(X,btype) |
|
32 |
|
33 if nargin<2 |
|
34 btype='stack'; |
|
35 end |
|
36 if isstr(btype)~=1 |
|
37 error('second argument has to be a string!!!!'); |
|
38 end |
|
39 |
|
40 barwidth=0.8; |
|
41 bw2=barwidth/2; |
|
42 |
|
43 ## uups. I did it the wrong way, this helps: |
|
44 X=X'; |
|
45 |
|
46 held = ishold; |
|
47 unwind_protect |
|
48 |
|
49 if min(size(X))==1 |
|
50 ## oh nice only single bars |
|
51 for jj=1:length(X) |
|
52 patch(jj + [-bw2, -bw2, bw2, bw2], [ 0, X(jj), X(jj), 0 ], 'r'); |
|
53 hold on |
|
54 endfor |
|
55 else |
|
56 if btype=='group' |
|
57 ## we have to change the barwidth: |
|
58 barwidth=0.8; |
|
59 bw=barwidth; |
|
60 for jj=1:size(X,1) |
|
61 for kk=1:size(X,2) |
|
62 patch(jj + ([-1,-1,0,0]+kk-size(X,2)/2)./size(X,2)*bw,... |
|
63 [ 0, X(jj,kk), X(jj,kk), 0 ], num2str(kk)); |
|
64 hold on |
|
65 endfor |
|
66 endfor |
|
67 elseif btype=='stack' |
|
68 for jj=1:size(X,1) |
|
69 for kk=1:size(X,2) |
|
70 patch(jj + [-bw2, -bw2, bw2, bw2],... |
|
71 sum(X(jj,1:kk-1)) + [0,X(jj,kk),X(jj,kk),0], num2str(kk)); |
|
72 hold on |
|
73 endfor |
|
74 endfor |
|
75 else |
|
76 error("patch: unknown type %s; use 'stack' or 'group'", btype); |
|
77 endif |
|
78 endif |
|
79 |
|
80 unwind_protect_cleanup |
|
81 if (!held) hold off; end; |
|
82 end_unwind_protect |
|
83 |
|
84 endfunction |