| 1 |
function scaleout = fn_multigraphn_ver2(imfn,... |
| 2 |
xlab,ylab,tstring,XTick,YTickIndx,scaleIndx,nrowg,ncolg) |
| 3 |
%Stacking n sets of impulse responses in one graph. See fn_multigraph2_ver2.m. |
| 4 |
% imfn: row: "nstp" time horizon (in the graphics), |
| 5 |
% column: "nrow "variables such as responses (row in the graphics), |
| 6 |
% 3rd D: across "ncol" different situations such as shocks (column in the graphics), |
| 7 |
% 4th D: across different scenarios such as error bands or different models (in each graph). |
| 8 |
% xlab: x-axis labels on the top |
| 9 |
% ylab: y-axis labels on the left |
| 10 |
% tstring: string for time (e.g., month or quarter) -- x-axis labels at the bottom |
| 11 |
% YTickIndx: 1: enable YTick; 0: disable; |
| 12 |
% To get a better picture, it is sometimes better to set YtickIndx to zero. |
| 13 |
% scaleIndx: 1: enable scale along Y-axis; 0: disable |
| 14 |
% nrowg: number of rows in the graph |
| 15 |
% ncolg: number of columns in the graph |
| 16 |
% |
| 17 |
% See imrgraph, imcerrgraph, imrerrgraph |
| 18 |
% |
| 19 |
% Copyright (C) 1997-2012 Tao Zha |
| 20 |
% |
| 21 |
% This free software: you can redistribute it and/or modify |
| 22 |
% it under the terms of the GNU General Public License as published by |
| 23 |
% the Free Software Foundation, either version 3 of the License, or |
| 24 |
% (at your option) any later version. |
| 25 |
% |
| 26 |
% It is distributed in the hope that it will be useful, |
| 27 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 |
% GNU General Public License for more details. |
| 30 |
% |
| 31 |
% If you did not received a copy of the GNU General Public License |
| 32 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 33 |
% |
| 34 |
|
| 35 |
nstp = size(imfn,1); |
| 36 |
nrow = size(imfn,2); |
| 37 |
ncol = size(imfn,3); |
| 38 |
nmodels = size(imfn,4); |
| 39 |
t = 1:nstp; |
| 40 |
|
| 41 |
if (nargin < 9) |
| 42 |
nrowg = nrow; |
| 43 |
ncolg = ncol; |
| 44 |
end |
| 45 |
if (nrowg*ncolg < nrow*ncol) |
| 46 |
nrowg |
| 47 |
ncolg |
| 48 |
nrow |
| 49 |
ncol |
| 50 |
|
| 51 |
error('fn_multigraphn_ver2.m: nrowg*ncolg must be greater than nrow*ncol') |
| 52 |
end |
| 53 |
|
| 54 |
|
| 55 |
tempmax=zeros(ncol,1); |
| 56 |
tempmin=zeros(ncol,1); |
| 57 |
maxval=zeros(nrow,1); |
| 58 |
minval=zeros(nrow,1); |
| 59 |
for i = 1:nrow |
| 60 |
for j = 1:ncol |
| 61 |
tempmax(j) = -realmax; |
| 62 |
tempmin(j) = realmax; |
| 63 |
for k=1:nmodels |
| 64 |
jnk = max(imfn(:,i,j,k)); |
| 65 |
tempmax(j) = max([jnk tempmax(j)]); |
| 66 |
% |
| 67 |
jnk = min(imfn(:,i,j,k)); |
| 68 |
tempmin(j) = min([jnk tempmin(j)]); |
| 69 |
end |
| 70 |
end |
| 71 |
maxval(i)=max(tempmax); |
| 72 |
minval(i)=min(tempmin); |
| 73 |
end |
| 74 |
|
| 75 |
scaleout = [maxval(:) minval(:)]; |
| 76 |
|
| 77 |
%-------------- |
| 78 |
% Column j: Shock 1 to N; Row i: Responses to |
| 79 |
%------------- |
| 80 |
%figure |
| 81 |
|
| 82 |
|
| 83 |
rowlabel = 1; |
| 84 |
for i = 1:nrow % column: from top to bottom |
| 85 |
columnlabel = 1; |
| 86 |
|
| 87 |
if minval(i)<0 |
| 88 |
if maxval(i)<=0 |
| 89 |
yt=[minval(i) 0]; |
| 90 |
else |
| 91 |
yt=[minval(i) 0 maxval(i)]; |
| 92 |
end |
| 93 |
else % (minval(i) >=0) |
| 94 |
if maxval(i) > 0 |
| 95 |
yt=[0 maxval(i)]; |
| 96 |
else % (identically zero responses) |
| 97 |
yt=[-1 0 1]; |
| 98 |
end |
| 99 |
end |
| 100 |
|
| 101 |
|
| 102 |
scale=[1 nstp minval(i) maxval(i)]; |
| 103 |
for j = 1:ncol % row: from left to right |
| 104 |
k1=(i-1)*ncol+j; |
| 105 |
subplot(nrowg,ncolg,k1) |
| 106 |
|
| 107 |
%set(0,'DefaultAxesColorOrder',[1 0 0;0 1 0;0 0 1],... |
| 108 |
% 'DefaultAxesLineStyleOrder','-|--|:') |
| 109 |
%set(0,'DefaultAxesLineStyleOrder','-|--|:|-.') |
| 110 |
set(0,'DefaultAxesColorOrder',[0 0 0],... |
| 111 |
'DefaultAxesLineStyleOrder','-|--|--|:*|-.|-*|--o|:d') |
| 112 |
|
| 113 |
nseries = zeros(nstp, nmodels); |
| 114 |
for k=1:nmodels |
| 115 |
nseries(:,k) = imfn(:,i,j,k); |
| 116 |
end |
| 117 |
plot(t,nseries, 'LineWidth',1.7); %,'Color','k'); |
| 118 |
%set(gca,'LineStyleOrder','-|--|:|-.') |
| 119 |
%set(gca,'LineStyleOrder',{'-*',':','o'}) |
| 120 |
grid; |
| 121 |
if scaleIndx |
| 122 |
axis(scale); |
| 123 |
end |
| 124 |
%set(gca,'YLim',[minval(i) maxval(i)]) |
| 125 |
% |
| 126 |
set(gca,'XTick',XTick) |
| 127 |
if YTickIndx |
| 128 |
set(gca,'YTick',yt) |
| 129 |
end |
| 130 |
|
| 131 |
if i<nrow |
| 132 |
set(gca,'XTickLabelMode','manual','XTickLabel',[]) |
| 133 |
end |
| 134 |
%set(gca,'XTickLabel',' '); |
| 135 |
if (scaleIndx) && (j>1) |
| 136 |
set(gca,'YTickLabel',' '); |
| 137 |
end |
| 138 |
if rowlabel == 1 |
| 139 |
%title(['x' num2str(j)]) |
| 140 |
%title(eval(['x' num2str(j)])) |
| 141 |
title(char(xlab(j))) |
| 142 |
end |
| 143 |
if columnlabel == 1 |
| 144 |
%ylabel(['x' num2str(i)]) |
| 145 |
%ylabel(eval(['x' num2str(i)])) |
| 146 |
ylabel(char(ylab(i))) |
| 147 |
end |
| 148 |
if i==nrow |
| 149 |
xlabel(tstring) |
| 150 |
end |
| 151 |
columnlabel = 0; |
| 152 |
end |
| 153 |
rowlabel = 0; |
| 154 |
end |
| 155 |
|
| 156 |
|
| 157 |
%Order of line styles and markers used in a plot. |
| 158 |
%This property specifies which line styles and markers to use and in what order |
| 159 |
%when creating multiple-line plots. For example,set(gca,'LineStyleOrder', '-*|:|o')sets LineStyleOrder to solid line with asterisk |
| 160 |
%marker, dotted line, and hollow circle marker. The default is (-), which specifies |
| 161 |
%a solid line for all data plotted. Alternatively, you can create a cell array |
| 162 |
%of character strings to define the line styles:set(gca,'LineStyleOrder',{'-*',':','o'})MATLAB supports four line styles, which you can specify any number of |
| 163 |
%times in any order. MATLAB cycles through the line styles only after using |
| 164 |
%all colors defined by the ColorOrder property. For example, |
| 165 |
%the first eight lines plotted use the different colors defined by ColorOrder with |
| 166 |
%the first line style. MATLAB then cycles through the colors again, using the |
| 167 |
%second line style specified, and so on.You can also specify line style and color directly with the plot and plot3 functions |
| 168 |
%or by altering the properties of theline or |
| 169 |
%lineseries objects after creating the graph. High-Level Functions and LineStyleOrderNote that, if the axes NextPlot property is set |
| 170 |
%to replace (the default), high-level functions like plot reset |
| 171 |
%the LineStyleOrder property before determining the line |
| 172 |
%style to use. If you want MATLAB to use a LineStyleOrder that |
| 173 |
%is different from the default, set NextPlot to replacechildren. Specifying a Default LineStyleOrderYou can also specify your own default LineStyleOrder. |
| 174 |
%For example, this statementset(0,'DefaultAxesLineStyleOrder',{'-*',':','o'}) |
| 175 |
%creates a default value for |