-
Notifications
You must be signed in to change notification settings - Fork 10
/
fs_titling.m
78 lines (66 loc) · 2.61 KB
/
fs_titling.m
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
%% Matlab Graph Titling, Labels and Legends Examples
% *back to* <https://fanwangecon.github.io *Fan*>*'s* <https://fanwangecon.github.io/Math4Econ/
% *Intro Math for Econ*>*,* <https://fanwangecon.github.io/M4Econ/ *Matlab Examples*>*,
% or* <https://fanwangecon.github.io/MEconTools/ *MEconTools*> *Repositories*
%% *Draw A figure Label Title, X and Y Axises with Latex Equations*
clear all;
close all;
figure();
% draw some lines
xline0 = xline(0);
xline0.HandleVisibility = 'off';
yline0 = yline(0);
yline0.HandleVisibility = 'off';
hline = refline([1 0]);
hline.Color = 'k';
hline.LineStyle = ':';
hline.HandleVisibility = 'off';
% Titling with multiple lines
title({'Cash-on-Hand given w(k+b),k,z' '$\alpha + \beta = \zeta$'},'Interpreter','latex');
ylabel({'Cash-on-Hand' 'line 2 $\frac{1}{2}$'},'Interpreter','latex');
xlabel({'Index of Cash-on-Hand Discrete Point'...
' $\frac{1}{2} + \alpha + \max + \sum_1^{B}$ Each Segment is a w=k+b; within segment increasing k'...
'For each w and z, coh maximizing k is different'},'Interpreter','latex');
grid on;
grid minor;
%% Matlab Graph Specify Legends Manually
% Specify labels manually, note we can use HandleVisibility to control what
% part of figure show up in legends.
% Generate Random Data
rng(123);
it_x_n = 10;
it_x_groups_n = 3;
mat_y = rand([it_x_n, it_x_groups_n]);
mat_y = mat_y + sqrt(1:it_x_groups_n);
mat_y = mat_y + log(1:it_x_n)';
ar_x = 1:1:it_x_n;
% Start Figure
figure('PaperPosition', [0 0 10 10]);
hold on;
g1 = scatter(ar_x, mat_y(:,1), 30, 'filled');
g2 = scatter(ar_x, mat_y(:,2), 30, 'filled');
g3 = scatter(ar_x, mat_y(:,3), 30, 'filled');
legend([g1, g2, g3], {'near','linear','spline'}, 'Location','best',...
'NumColumns',1,'FontSize',12,'TextColor','black');
% PLot this line, but this line will not show up in legend
hline = refline([1 0]);
hline.Color = 'k';
hline.LineStyle = ':';
% not to show up in legend
hline.HandleVisibility = 'off';
grid on;
grid minor;
title(sprintf('griddedInterpolant comparison, crra utility approximation, interp grid n=%d', it_x_n))
ylabel('Actual Utility Evaluated at c')
xlabel('Approximated Util based on Interpolation')
snapnow;
%% Given Graph, Graph Subset of Lines and Add Extra Line with Legend
% Same plot as before, except we plot only 2 of the three lines and add another
% line with associated legend entry.
legendCell = cellstr(num2str(ar_x', 'shock=%3.2f'));
xlinemax = xline(min(mat_y, [], 'all'));
xlinemax.Color = 'b';
xlinemax.LineWidth = 1.5;
legendCell{length(legendCell) + 1} = 'max-agg-save';
legend([g1, g3, xlinemax], legendCell([1,3,length(legendCell)]), 'Location', 'best');
snapnow;