File: scatter_plots.m

package info (click to toggle)
dynare 5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 77,852 kB
  • sloc: cpp: 94,481; ansic: 28,551; pascal: 14,532; sh: 5,453; objc: 4,671; yacc: 4,442; makefile: 2,923; lex: 1,612; python: 677; ruby: 469; lisp: 156; xml: 22
file content (189 lines) | stat: -rw-r--r-- 6,447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
function scatter_plots(X,xp,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, DynareOptions)
%
% Written by Marco Ratto
% Joint Research Centre, The European Commission,
% marco.ratto@ec.europa.eu
%

% Copyright (C) 2017 European Commission
% Copyright (C) 2017 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <https://www.gnu.org/licenses/>.

% PURPOSE: Pairwise scatter plots of the columns of x and y after
% Monte Carlo filtering
%---------------------------------------------------
% USAGE:    scatter_mcf(x,y,vnames,pltsym,diagon)
%        or scatter_mcf(x,y) which relies on defaults
% where:
%        x = an nxk matrix with columns containing behavioural sample
%        y = an mxk matrix with columns containing non-behavioural sample
%   vnames = a vector of variable names
%            (default = numeric labels 1,2,3 etc.)
%   pltsym = a plt symbol
%            (default = '.' for npts > 100, 'o' for npts < 100


[n,p] = size(X);
% X = X - ones(n,1)*min(Z);
% X = X ./ (ones(n,1)*max(Z));

nflag = 0;
if nargin >=3
    nflag = 1;
end

if nargin<4 || isempty(plotsymbol)
    if n*p<100, plotsymbol = 'o';
    else plotsymbol = '.';
    end
end

if nargin<5 || isempty(fnam)
    fnam='scatter_plot';
end
if nargin<6 || isempty(dirname)
    dirname='';
    nograph=1;
    DynareOptions.nodisplay=0;
else
    nograph=0;
end
if nargin<7 || isempty(figtitle)
    figtitle=fnam;
end
if nargin<8
    xparam1=[];
end

figtitle_tex=strrep(figtitle,'_','\_');

fig_nam_=[fnam];

hh=dyn_figure(DynareOptions.nodisplay,'name',figtitle);
set(hh,'userdata',{X,xp})

bf = 0.1;
ffs = 0.05/(p-1);
ffl = (1-2*bf-0.05)/p;
if p>1
    fL = linspace(bf,1-bf+ffs,p+1);
else
    fL = bf;
end
for i = 1:p
    for j = 1:p
        h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]);
        if i==j
            h1=cumplot(X(:,j));
            set(h,'Tag','cumplot')
            %             set(h1,'color',[0 0 1], 'linestyle','--','LineWidth',1.5)
            set(h1,'color',[0 0 1],'LineWidth',1.5)
            if ~isempty(xparam1)
                hold on, plot(xparam1([j j]),[0 1],'k--')
            end
            if j<p
                set(gca,'XTickLabel',[],'XTick',[]);
            else
                grid off
            end
            set(gca,'YTickLabel',[],'YTick',[]);
        else
            if j>i
                plot(X(:,i),X(:,j),[plotsymbol,'b'])
            else
                plot(X(:,i),X(:,j),[plotsymbol,'b'])
            end
            set(h,'Tag','scatter')

            %%
            if ~isoctave
                % Define a context menu; it is not attached to anything
                hcmenu = uicontextmenu('Callback','pick','Tag','Run viewer');
                % Define callbacks for context menu
                % items that change linestyle
                hcb1 = 'scatter_callback';
                % hcb2 = ['set(gco,''LineStyle'','':'')'];
                % hcb3 = ['set(gco,''LineStyle'',''-'')'];
                % % Define the context menu items and install their callbacks
                item1 = uimenu(hcmenu,'Label','save','Callback',hcb1,'Tag','save params');
                item2 = uimenu(hcmenu,'Label','eval','Callback',hcb1,'Tag','eval params');
                % item3 = uimenu(hcmenu,'Label','solid','Callback',hcb3);
                % Locate line objects
                hlines = findall(h,'Type','line');
                % Attach the context menu to each line
                for line = 1:length(hlines)
                    set(hlines(line),'uicontextmenu',hcmenu)
                end
            end
            %%
            if ~isempty(xparam1)
                hold on, plot(xparam1(i),xparam1(j),'s','MarkerFaceColor',[0 0.75 0],'MarkerEdgeColor',[0 0.75 0])
            end
            hold off;
            %             axis([-0.1 1.1 -0.1 1.1])
            if i<p
                set(gca,'YTickLabel',[],'YTick',[]);
            else
                set(gca,'yaxislocation','right');
            end
            if j<p
                set(gca,'XTickLabel',[],'XTick',[]);
            end
        end
        if nflag == 1
            set(gca,'fontsize',9);
        end
        if i==1
            if nflag == 1
                ylabel(vnames(j,:),'Rotation',45,'interpreter','none', ...
                       'HorizontalAlignment','right','VerticalAlignment','middle');
            else
                ylabel([num2str(j),' '],'Rotation',90)
            end
        end
        if j==1
            if nflag == 1
                title(vnames(i,:),'interpreter','none','Rotation',45, ...
                      'HorizontalAlignment','left','VerticalAlignment','bottom')
            else
                title(num2str(i))
            end
        end
        drawnow
    end
end
% if ~isoctave
%     annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center','interpreter','none');
%     annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center','interpreter','none');
% end

if ~nograph
    dyn_saveas(hh,[dirname,filesep,fig_nam_],DynareOptions.nodisplay,DynareOptions.graph_format);
    if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format)))
        fidTeX = fopen([dirname,'/',fig_nam_ '.tex'],'w');
        fprintf(fidTeX,'%% TeX eps-loader file generated by scatter_plots.m (Dynare).\n');
        fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
        fprintf(fidTeX,'\\begin{figure}[H]\n');
        fprintf(fidTeX,'\\centering \n');
        fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s}\n',strrep([dirname,'/',fig_nam_],'\','/'));
        fprintf(fidTeX,'\\caption{%s.}',figtitle_tex);
        fprintf(fidTeX,'\\label{Fig:%s}\n',fig_nam_);
        fprintf(fidTeX,'\\end{figure}\n\n');
        fprintf(fidTeX,'%% End Of TeX file. \n');
        fclose(fidTeX);
    end
end