Skip to content

Commit 2a468ee

Browse files
authored
Adds options to plotRefSLD (#270)
1 parent 2a0cdda commit 2a468ee

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

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.showErrorBar {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.showErrorBar, ...
26+
options.showGrid, options.showLegend);
1727
end

utilities/plotting/plotRefSLDHelper.m

Lines changed: 49 additions & 14 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, showErrorBar, showGrid, showLegend)
2+
% Helper function to make it easier to plot from event.
3+
%
4+
% - Data is a struct with the plot data.
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+
showErrorBar {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,54 @@ 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;
46+
q4Data = 1;
2547
for i = 1:numberOfContrasts
2648
thisRef = data.reflectivity{i};
2749
thisData = data.shiftedData{i};
28-
if i == 1
29-
mult = 1;
30-
else
50+
if i > 1 || q4
3151
mult = 2^(4*i);
3252
end
33-
53+
54+
if q4 && data.dataPresent(i)
55+
q4Data = thisData(:,1).^4;
56+
end
57+
mult = q4Data/mult;
58+
refY = thisRef(:,2) .* mult;
3459
% If there is data present
3560
% plot it - size of data.shiftedData
3661
% 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);
62+
if data.dataPresent(i) && showErrorBar
63+
dataX = thisData(:, 1);
64+
dataY = thisData(:,2) .* mult;
65+
dataErr = thisData(:,3) .* mult;
66+
errorbar(dataX, dataY, dataErr, '.', 'MarkerSize', 2.5);
3967
end
4068

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

4472
end
45-
legend([lines{:}], data.contrastNames{:});
73+
if showLegend
74+
legend([lines{:}], data.contrastNames{:});
75+
end
4676

4777
% Plot the SLDs
4878
subplot(1,2,2);
79+
if showGrid
80+
set(gca,'YGrid','on','XGrid','on');
81+
end
4982
hold on
5083
nColumns = size(data.sldProfiles, 2);
5184
lines = cell(numberOfContrasts * nColumns, 1);
@@ -85,7 +118,9 @@ function plotRefSLDHelper(data, noDelay)
85118
end
86119
end
87120
end
88-
legend([lines{:}], names{:});
121+
if showLegend
122+
legend([lines{:}], names{:});
123+
end
89124
if noDelay
90125
drawnow limitrate;
91126
end

0 commit comments

Comments
 (0)