Skip to content

Commit cd32ce9

Browse files
committed
Adds options to plotRefSLD
1 parent e206795 commit cd32ce9

2 files changed

Lines changed: 62 additions & 15 deletions

File tree

utilities/plotting/plotRefSLD.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
function plotRefSLD(problem, result)
1+
function plotRefSLD(problem, result, options)
2+
arguments
3+
problem
4+
result
5+
options.linearX {logical} = false
6+
options.q4 {logical} = false
7+
options.showErrorBars {logical} = true
8+
options.showGrid {logical} = false
9+
options.showLegend {logical} = true
10+
end
211
% Convert the problem class to a struct.
312
controls = controlsClass();
413
data.modelType = problem.modelType;
@@ -13,5 +22,6 @@ function plotRefSLD(problem, result)
1322
data.resample = problemStruct.resample;
1423
data.contrastNames = cells{21};
1524

16-
plotRefSLDHelper(data, false);
25+
plotRefSLDHelper(data, false, options.linearX, options.q4, options.showErrorBars, ...
26+
options.showGrid, options.showLegend);
1727
end

utilities/plotting/plotRefSLDHelper.m

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
function plotRefSLDHelper(data, noDelay)
2-
% Helper function to make it easier to plot from event. Data is a struct
3-
% with the plot data and noDelay indicates if draw should be delayed.
1+
function plotRefSLDHelper(data, noDelay, linearX, q4, showErrorBars, showGrid, showLegend)
2+
% Helper function to make it easier to plot from event.
3+
%
4+
% - Data is a struct with the plot data and
5+
% - noDelay indicates if draw should be delayed.
6+
% - linearX indicates that the X axis should be linear scale instead of log
7+
% - q4 indicates that the Y axis should plot Q^4
8+
% - showErrorBars indicates that the error bar should be shown in the plot
9+
% - showGrid indicates that the grid should be shown in the plot
10+
% - showLegend indicates that the legend should be shown in the plot
411
%
512
% plotRefSLDHelper(data, false);
613
arguments
714
data
815
noDelay {logical} = true
16+
linearX {logical} = true
17+
q4 {logical} = true
18+
showErrorBars {logical} = true
19+
showGrid {logical} = false
20+
showLegend {logical} = true
921
end
10-
22+
1123
defaultState = 'on';
1224
s = warning();
1325
if any(strcmp({s.identifier}, 'MATLAB:Axes:NegativeDataInLogAxis'))
@@ -19,33 +31,56 @@ function plotRefSLDHelper(data, noDelay)
1931

2032
% Plot the data.reflectivity
2133
subplot(1,2,1);
22-
set(gca,'YScale','log','XScale','log');
34+
if linearX
35+
set(gca,'YScale','log','XScale','linear');
36+
else
37+
set(gca,'YScale','log','XScale','log');
38+
end
39+
40+
if showGrid
41+
set(gca,'YGrid','on','XGrid','on');
42+
end
2343
hold on
2444
lines = cell(numberOfContrasts, 1);
45+
mult = 1;
2546
for i = 1:numberOfContrasts
2647
thisRef = data.reflectivity{i};
2748
thisData = data.shiftedData{i};
28-
if i == 1
29-
mult = 1;
30-
else
49+
if i > 1 || q4
3150
mult = 2^(4*i);
3251
end
52+
dataX = thisData(:, 1);
53+
dataY = thisData(:,2)./mult;
54+
dataErr = thisData(:,3)./mult;
55+
refY = thisRef(:,2)./mult;
56+
57+
if q4
58+
q4Data = thisData(:,1).^4;
59+
dataY = dataY(:) .* q4Data;
60+
dataErr = dataErr(:) .* q4Data;
61+
refY = refY(:) .* q4Data;
62+
end
3363

3464
% If there is data present
3565
% plot it - size of data.shiftedData
3666
% will be [n x 3] if so
37-
if data.dataPresent(i)
38-
errorbar(thisData(:,1),thisData(:,2)./mult,thisData(:,3)./mult,'.','MarkerSize',2.5);
67+
if data.dataPresent(i) && showErrorBars
68+
errorbar(dataX, dataY, dataErr, '.', 'MarkerSize', 2.5);
3969
end
4070

4171
% Plot the fit
42-
lines{i} = plot(thisRef(:,1),thisRef(:,2)./mult,'-','LineWidth',2);
72+
lines{i} = plot(thisRef(:,1), refY, '-', 'LineWidth', 2);
4373

4474
end
45-
legend([lines{:}], data.contrastNames{:});
75+
if showLegend
76+
legend([lines{:}], data.contrastNames{:});
77+
end
4678

4779
% Plot the SLDs
4880
subplot(1,2,2);
81+
if showGrid
82+
set(gca,'YGrid','on','XGrid','on');
83+
end
4984
hold on
5085
nColumns = size(data.sldProfiles, 2);
5186
lines = cell(numberOfContrasts * nColumns, 1);
@@ -85,7 +120,9 @@ function plotRefSLDHelper(data, noDelay)
85120
end
86121
end
87122
end
88-
legend([lines{:}], names{:});
123+
if showLegend
124+
legend([lines{:}], names{:});
125+
end
89126
if noDelay
90127
drawnow limitrate;
91128
end

0 commit comments

Comments
 (0)