-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_audiogram.m
More file actions
96 lines (84 loc) · 3.01 KB
/
plot_audiogram.m
File metadata and controls
96 lines (84 loc) · 3.01 KB
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
function [hFig] = plot_audiogram(hFig, freq, threshs, xLimits, yLimits, plotColour, ind_threshs, ind_colour, save_file)
% [hFig] = plot_audiogram(hFig, freq, threshs, xLimits, yLimits, ...
% plotColour, ind_threshs, ind_colour, save_file)
% hFig Handle for figure or axis. To create new, pass empty
% vector.
% freq Vector containing frequencies to plot.
% threshs Vector containing threshold values to plot.
% xLimits 2-element vector containing upper and lower bounds of
% x-axis (frequencies). Default = [0, 8000].
% yLimits 2-element vector containing upper and lower bounds of
% y-axis (thresholds). Default = [-10, 60].
% plotColour MATLAB ColorSpec, e.g., 'r' or [1, 0, 0].
% ind_threshs N x freq matrix specifying thresholds for individual
% participants to plot on graph. If empty, does not plot
% individual participants.
% ind_colour N x 3 matrix of RGB color values, corresponding to the
% individual thresholds specified in ind_thresh.
% save_file String containing filepath to save plot. If empty
% vector passed, plot not saved.
%
% Emma Holmes
% Created on 18/04/2018
% Define visual properties of bar graph
markerSize = 30;
lineWidth = 1.5;
indWidth = 0.5;
xTitle = 'Frequency';
yTitle = 'Threshold (dB HL)';
% Draw figure
if isempty(hFig)
hFig = figure;
else
try
figure(hFig);
catch
axis(hFig);
end
end
hold on;
% Set x- and y-limits to defaults if empty
if isempty(xLimits)
xLimits = [0, 8000];
end
if isempty(yLimits)
yLimits = [-10, 60];
end
% Draw individual points on graph
if ~isempty(ind_threshs)
for p = 1 : size(ind_threshs, 1)
hLine = plot(freq, ind_threshs(p,:), 'Color', ind_colour(p,:), ...
'Marker', '.', 'MarkerSize', markerSize, 'LineWidth', indWidth);
uistack(hLine, 'bottom');
end
end
% Draw thresholds
for t = 1 : size(threshs, 1)
plot(freq, threshs(t,:), 'Color', plotColour, 'Marker', '.', ...
'MarkerSize', markerSize, 'LineWidth', lineWidth);
end
% Draw x=0 and y=0
hX = plot([0, 0], yLimits, 'k', 'LineWidth', lineWidth);
hY = plot(xLimits, [0, 0], 'k', 'LineWidth', lineWidth);
uistack([hX, hY], 'bottom');
% Add grid lines
grid(gca, 'on');
% Format graph style
xlim(xLimits);
ylim(yLimits);
format_graph(gca, xTitle, yTitle);
box on;
set(gcf, 'Position', [692, 317, 521, 568])
% Reverse direction of y-axis
set(gca, 'YDir', 'reverse');
% Set x-axis to log scale and set tick labels to frequencies
set(gca, 'XScale', 'log');
xticks(freq);
yticks(yLimits(1) : 10 : yLimits(end));
set(gca, 'GridColor', 'k', 'MinorGridLineStyle', 'none', ...
'XMinorTick', 'off', 'Layer', 'bottom');
% Save plot
if ~isempty(save_file)
set(gcf, 'PaperPositionMode', 'auto');
print(gcf, save_file, '-dtiff', '-r300');
end