forked from sgarrettroe/data_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrb2dPlot.m
213 lines (194 loc) · 5.74 KB
/
rb2dPlot.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
function varargout = rb2dPlot(varargin)
% rb2dPlot: plots a 2d spectrum
%
% 20110528, RB: started the function
%
% INPUT:
% either: a struct, it will plot the 2D spectrum
% or: x_axis, y_axis, data, it will plot this
% the x_axis and y_axis should correspond to the size of the matrix
% CONTRARY TO my2dPlot THESE ARE THE WHOLE AXIS, NOT THE PART YOU WANT TO
% PLOT!!!
%
% other INPUT:
% - xlim, ylim (opt): the limits for the x and y axes. [0 0] means
% the whole range will be plotted, [0 -1] means that the other axis will be
% used for the range and [n m] means that range will be plotted. In case of
% errors (out of range etc) it will fall back to plot everything. Default
% is xlim = [0 0] and ylim = [0 -1].
%
% - zlimit (opt), number: will change the intensity range. 0 means
% everything is plotted (default). 0 < zlimit <= 1 will plot a range.
% zlimit > 1 will plot an absolute value. The zlimit is always symmetric
% around 0.
%
% - n_contours (opt), number: the amount of contours. Using an odd number will give a
% warning. Default is 12.
%
% - pumprobe (opt), BOOL: changes the axes. Default is FALSE.
%
% - title (opt), string: a title will be given to the plot.
%
% - no_units (opt), BOOL: will plot the spectrum, but with pixel and step
% number instead of the frequency axis.
%
% - brightness (opt), number: best left alone. It changes the range of
% colors plotted. The lower the number, the brighter the colors. Default is
% 0.2, which means the range over which the color changes is 0.8.
% set variables
n_contours = 12;
zlimit = 0;
flag_pumpprobe = false;
xlim = [0 0];
ylim = [0 -1];
title_string = '';
flag_no_units = false;
flag_no_title = false;
flag_no_horizontal_labels = false;
flag_no_vertical_labels = false;
x_label = '\omega_3 / 2\pic';
y_label = '\omega_1 / 2\pic';
brightness = 0.2;
flag_debug = false;
line_width = 1;
%disp(varargin)
% read varargin (part I)
if isa(varargin{1}, 'struct')
x_axis = varargin{1}.w3;
y_axis = varargin{1}.w1;
data = varargin{1}.R;
varargin = varargin(2:end);
else
x_axis = varargin{1};
y_axis = varargin{2};
data = varargin{3};
varargin = varargin(4:end);
end
% read varargin
while length(varargin) >= 2
arg = varargin{1};
val = varargin{2};
switch lower(arg)
case 'xlim'
xlim = val;
case 'ylim'
ylim = val;
case 'zlimit'
zlimit = val;
case 'n_contours'
n_contours = val;
case 'pumpprobe'
flag_pumpprobe = val;
case 'title'
title_string = val;
case 'no_units'
flag_no_units = val;
case 'line_width'
line_width = val;
case 'brightness'
brightness = val;
case 'debug'
flag_debug = val;
case 'xlabel'
x_label = val;
case 'ylabel'
y_label = val;
case 'no_title'
flag_no_title = val;
case 'no_vertical_labels'
flag_no_vertical_labels = val;
case 'no_horizontal_labels'
flag_no_horizontal_labels = val;
otherwise
error(['rb2dPlot: unknown option ', arg]);
end
varargin = varargin(3:end);
end
% error checking
if mod(n_contours,2)
warning('rb2dPlot: Odd number of contour lines may produce unexpected results!')
end
% determine the x and y axes
if xlim == [0 0]
xrange = find(x_axis);
if ylim == [0 0]
yrange = find(y_axis);
elseif ylim == [0 -1]
yrange = find(y_axis >= x_axis(1) & y_axis <= x_axis(end));
else
yrange = find(y_axis >= ylim(1) & y_axis <= ylim(end));
end
elseif xlim == [0 -1]
if ylim == [0 0]
yrange = find(y_axis);
xrange = find(x_axis >= y_axis(1) & x_axis <= y_axis(end));
elseif ylim == [0 -1]
yrange = find(y_axis);
xrange = find(x_axis);
else
yrange = find(y_axis >= ylim(1) & y_axis <= ylim(end));
xrange = find(x_axis >= y_axis(1) & x_axis <= y_axis(end));
end
else
xrange = find(x_axis >= xlim(1) & x_axis <= xlim(end));
if ylim == [0 0]
yrange = find(y_axis);
elseif ylim == [0 -1]
yrange = find(y_axis >= xlim(1) & y_axis <= xlim(end));
else
yrange = find(y_axis >= ylim(1) & y_axis <= ylim(end));
end
end
% set the x, y, and z
if flag_no_units
x = xrange;
y = yrange;
else
x = x_axis(xrange);
y = y_axis(yrange);
end
z = data(yrange,xrange);
% load the color scheme
map = [];
map = myMapRGB2(n_contours, brightness);
if flag_debug; disp('rb2dPlot: color map:'); disp(map); end
% determine the range to be plotted
level_list = [];
if zlimit <= 0
% 0: use the whole range
[ca, level_list] = myCaxis2(z, n_contours);
elseif zlimit > 0 && zlimit <= 1
% 0 < zlimit <= 1: plot a ratio
[ca, level_list] = myCaxis2(z, n_contours);
ca = ca * zlimit;
level_list = level_list * zlimit;
else
% otherwise, plot between abs. values
ca = [-zlimit zlimit];
level_list = linspace(-zlimit, zlimit, n_contours+2);
end
if flag_debug; disp(['rb2dPlot: contour levels:' num2str(ca(1)) ', ' num2str(ca(2))]); end
if flag_debug; disp('rb2dPlot: level_list:'); disp(level_list); end
%disp(ca);
title_string = [title_string num2str(level_list(end))];
% plot, use colormap and set axes
contourf(x, y, z, level_list, 'LineWidth', line_width);
colormap(map);
% since we have the level_list, we don't need the caxis
caxis(ca);
% diagonal line
line([x(1) x(end)], [x(1) x(end)], 'Color',[0 0 0], 'LineWidth', line_width);
% labels for the plot
if flag_no_units
x_label = 'pixels';
y_label = 'step';
end
if ~flag_no_horizontal_labels
xlabel(x_label); %, 'FontSize', line_width * 10);
end
if ~flag_no_vertical_labels
ylabel(y_label); %, 'FontSize', line_width * 10);
end
if ~flag_no_title
title(title_string); %, 'FontSize', line_width * 10);
end