-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtgPlot.m
More file actions
86 lines (78 loc) · 2.79 KB
/
Copy pathtgPlot.m
File metadata and controls
86 lines (78 loc) · 2.79 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
function tgPlot(tg, subPlotStartIndex)
% function tgPlot(tg, subPlotStartIndex)
%
% Plots TextGrid.
%
% subPlotStartIndex: optional argument, it indicates the initial index of
% subplot where the first tier is going to be plotter. It is useful, e.g,
% in a situation when we want to draw a wave in the first position, a
% PitchTier in a second position, and begin tiers of the textgrid in the
% third position. Then, the total number of subplot panels is
% subplot(ntiers + subPlotStartIndex - 1, 1, ...)
%
% v1.0, Tomas Boril, borilt@gmail.com
%
% Example
% tg = tgRead('demo/H.TextGrid');
% tgPlot(tg);
%
% figure
% pt = ptRead('demo/H.PitchTier');
% tgPlot(tg, 2);
% subplot(tgGetNumberOfTiers(tg)+1, 1, 1);
% ptPlot(pt);
if nargin == 1
subPlotStartIndex = 1;
elseif nargin == 2
if ~isInt(subPlotStartIndex) || subPlotStartIndex < 1
error(['subPlotStartIndex must be integer >= 1 [' num2str(subPlotStartIndex) ']']);
end
else
error('Wrong number of arguments.')
end
ntiers = tgGetNumberOfTiers(tg);
if ntiers == 0
subplot 111
title('Empty TextGrid')
end
for I = 1: ntiers
subplot(ntiers + subPlotStartIndex - 1, 1, I + subPlotStartIndex - 1)
if tgIsPointTier(tg, I)
% title('point tier')
StemHandle = stem(tg.tier{I}.T, 2*0.5*ones(size(tg.tier{I}.T)), 'fill', 'MarkerSize', 2);
Xd = get(StemHandle, 'XData');
Yd = get(StemHandle, 'YData');
for K = 1 : length(Xd)
lab = tg.tier{I}.Label{K};
lab = strrep(lab, '\', '\\'); lab = strrep(lab, '_', '\_');
lab = strrep(lab, '^', '\^'); lab = strrep(lab, '{', '\{');
lab = strrep(lab, '}', '\}');
text(Xd(K), Yd(K) * 1.3, lab, 'HorizontalAlignment', 'center');
end
axis([tg.tmin tg.tmax 0 2])
set(gca,'YTick',[])
elseif tgIsIntervalTier(tg, I)
% title('interval tier')
StemHandle = stem(tg.tier{I}.T1, 2*0.8*ones(size(tg.tier{I}.T1)), 'MarkerSize', 1);
hold on
stem(tg.tier{I}.T2, 2*0.5*ones(size(tg.tier{I}.T2)), 'MarkerSize', 1);
for K = 1: length(tg.tier{I}.T1)
plot([tg.tier{I}.T1(K) tg.tier{I}.T2(K)], 2*[0.5 0.5]);
end
hold off
Xd = get(StemHandle, 'XData');
Yd = get(StemHandle, 'YData');
for K = 1 : length(Xd)
lab = tg.tier{I}.Label{K};
lab = strrep(lab, '\', '\\'); lab = strrep(lab, '_', '\_');
lab = strrep(lab, '^', '\^'); lab = strrep(lab, '{', '\{');
lab = strrep(lab, '}', '\}');
text(Xd(K), Yd(K) * (1.3*0.5)/(0.8), lab, 'HorizontalAlignment', 'left');
end
axis([tg.tmin tg.tmax 0 2])
set(gca,'YTick',[])
else
error('unknown tier type')
end
ylabel(tg.tier{I}.name);
end