source: issm/trunk/src/m/qmu/plot/plot_rlev_bars.m@ 4763

Last change on this file since 4763 was 4763, checked in by Eric.Larour, 15 years ago

Moved plotting routines to qmu/plot directory

File size: 4.8 KB
Line 
1%
2% plot a stacked bar chart of the response levels in the cdf.
3%
4% []=plot_rlev_bars(dresp ,params)
5% []=plot_rlev_bars(dresp,descr,params)
6%
7% where the required input is:
8% dresp (structure array, responses)
9% or
10% dresp (structure array, responses)
11% descr (cell array, list of response descriptions desired)
12%
13% the required fields of dresp are:
14% descriptor (char, description)
15% cdf(:,4) (double matrix, CDF table)
16%
17% the optional input is:
18% params (string/numeric, parameter names and values)
19%
20% where the optional parameters are:
21% ymin (numeric, minimum of y-axis)
22% ymax (numeric, maximum of y-axis)
23% xtlrot (numeric, rotation in degrees of x-tick labels)
24% lstr (cell array, legend labels)
25%
26% for each response in the input array, this function plots
27% a stacked bar plot of the responses, where the bars are
28% stacked by the response levels corresponding to the given
29% probabilities in the CDF, and annotates it with the
30% description. the legend labels can be given or constructed
31% from the probabilities.
32%
33% this data would typically be contained in the dakota output
34% file and read by dakota_out_parse.
35%
36% "Copyright 2009, by the California Institute of Technology.
37% ALL RIGHTS RESERVED. United States Government Sponsorship
38% acknowledged. Any commercial use must be negotiated with
39% the Office of Technology Transfer at the California Institute
40% of Technology. (J. Schiermeier, NTR 47078)
41%
42% This software may be subject to U.S. export control laws.
43% By accepting this software, the user agrees to comply with
44% all applicable U.S. export laws and regulations. User has the
45% responsibility to obtain export licenses, or other export
46% authority as may be required before exporting such information
47% to foreign countries or providing access to foreign persons."
48%
49function []=plot_rlev_bars(varargin)
50
51if ~nargin
52 help plot_rlev_bars
53 return
54end
55
56%% process input data and assemble into matrices and increments
57
58% responses
59
60iarg=1;
61if isstruct(varargin{iarg})
62 dresp=varargin{iarg};
63 iarg=iarg+1;
64
65% if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg}))
66 if iarg <= nargin && iscell(varargin{iarg})
67 dresp=struc_desc(dresp,varargin{iarg});
68 iarg=iarg+1;
69 end
70
71 descr=cell (1,length(dresp));
72 lcdfr=zeros(1,length(dresp));
73 for i=1:length(dresp)
74 lcdfr(i)=size(dresp(i).cdf,1);
75 end
76 cdfr=zeros(length(dresp),max(lcdfr));
77
78 for i=1:length(dresp)
79 descr(i)=cellstr(dresp(i).descriptor);
80 if ~isempty(dresp(i).cdf)
81 cdfr(i,1)=dresp(i).cdf(1,1);
82 for j=2:size(dresp(i).cdf,1)
83 if (dresp(i).cdf(j,1) > dresp(i).cdf(j-1,1))
84 cdfr(i,j)=dresp(i).cdf(j,1)-dresp(i).cdf(j-1,1);
85 end
86 end
87 end
88 end
89else
90 error(['''' inputname(iarg) ''' is not a structure.']);
91end
92
93% parameters
94
95while (iarg <= nargin-1)
96 if ischar(varargin{iarg})
97 eval([varargin{iarg} '=varargin{iarg+1};']);
98 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']);
99 else
100 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']);
101 end
102 iarg=iarg+2;
103end
104
105%% draw the stacked bar plot
106
107% if there's only one row, Matlab 7.5 interprets it as a column,
108% so add an extra row, then reduce xlim
109
110if length(dresp) == 1
111 cdfr=[cdfr; cdfr];
112end
113
114figure
115hl1=bar(cdfr,'stacked');
116% set barseries properties for lowest value
117whitebg('white')
118set(hl1(1),'FaceColor','white')
119set(hl1(1),'Visible','off')
120
121ax1=gca;
122if length(dresp) == 1
123 set(ax1,'xlim',[0.5 1.5])
124end
125
126ylim('auto')
127[ylims]=ylim;
128if exist('ymin','var')
129 ylims(1)=ymin;
130end
131if exist('ymax','var')
132 ylims(2)=ymax;
133end
134ylim(ylims)
135
136set(ax1,'xtick',1:length(descr))
137set(ax1,'xticklabel',descr)
138if exist('xtlrot','var')
139 htl=rotateticklabel(ax1,xtlrot);
140 tlext=zeros(length(htl),4);
141 for i=1:length(htl)
142 tlext(i,:)=get(htl(i),'Extent');
143 end
144end
145
146% add the annotation
147
148title('Response Levels for Specified Probabilities (PMA)')
149xlabel('Response');
150if exist('xtlrot','var')
151 xlext=get(get(ax1,'xlabel'),'Extent');
152 nskip=ceil(max(tlext(:,4))/xlext(4));
153 xlabel(cellstr([repmat(' ',nskip,1);'Response']));
154 clear nskip xlext tlext
155end
156ylabel('Response Level')
157
158if ~exist('lstr','var') || isempty(lstr)
159 lstr=cell(1,max(lcdfr));
160 for i=1:max(lcdfr)
161 lstr(i)=cellstr(sprintf('%g%%',...
162 100*dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,2)));
163 end
164 if ~isempty(find(lcdfr < max(lcdfr),1))
165 warning('Variable number of probabilities for responses.');
166 end
167end
168
169hleg1=legend(ax1,lstr,'Location','EastOutside',...
170 'Orientation','vertical','Interpreter','none');
171
172end
Note: See TracBrowser for help on using the repository browser.