This repository has been archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathft_pimpplot.m
162 lines (135 loc) · 4.23 KB
/
ft_pimpplot.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
function varargout = ft_pimpplot(hfig,cmap,pimp,set_printing_properties)
%--------------------------------------------------------------------------
% FT_PIMPPLOT can pimp single channel time frequency representations and
% topographical representations created by FieldTrip. Basically, it
% replots the plots created by imagesc and surface using contourf.
%
% See also FT_PLOT
%
% This file is a FieldTrip fork as part of the FieldTripWrapper toolbox
% Copyright (C) 2010, Lennart Verhagen
% version 2010-02-01
%--------------------------------------------------------------------------
% check input
if nargin < 4, set_printing_properties = true; end
if nargin < 3, pimp = true; end
if isempty(pimp), pimp = true; end
if nargin < 2, cmap = @jet; end
if nargin < 1, hfig = gcf; end
% set output
varargout = {};
if nargout > 0
varargout = {hfig};
end
% % return if requested
% if isfalse(pimp)
% return
% end
% specify number of steps in colormap
stps = 2^9;
% create colormap if needed
if isa(cmap,' function_handle')
cmap = cmap(stps);
end
% get images axes handles
hs = findobj(hfig,'Type','image','-and','Tag','cip');
ht = findobj(hfig,'Type','surface');
ha = findobj(hfig,'Type','axes');
% pimp the single channel time-frequency representation
for i = 1:length(hs)
% get title and data
%title_str = get(get(get(hs(i),'Parent'),'Title'),'String');
X = get(hs(i),'XData');
Y = get(hs(i),'YData');
Z = get(hs(i),'CData');
A = get(hs(i),'AlphaData');
%c = caxis(get(hs(i),'Parent'));
% expand matrix. This is necessary because the original plot was made
% using image
x_step = mode(abs(diff(X)));
y_step = mode(abs(diff(Y)));
X = [X(1)-x_step X X(end)+x_step];
Y = [Y(1)-y_step Y Y(end)+y_step];
Z = [Z(:,1) Z Z(:,end)];
Z = [Z(1,:); Z; Z(end,:)];
A = [A(:,1) A A(:,end)];
A = [A(1,:); A; A(end,:)];
% create new figure if requested
if pimp < 0
if ~exist('hnfig','var')
hnfig = copyobj(hfig,0);
end
figure(hfig);
end
% re-plot data using contourf
set(hfig,'CurrentAxes',get(hs(i),'Parent'));
delete(hs(i));
hold on;
[C,hn] = contourf(X,Y,Z,stps,'LineStyle','none');
colormap(cmap);
set(gca,'Box','off');
axis([min(X)+x_step/2 max(X)-x_step/2 min(Y)+y_step/2 max(Y)-y_step/2]);
% axis tight;
% add the alpha-map from the original image
if ~all(A(:))
whitemat = ones([size(A) 3]);
A(A>=1) = 0; % A(A> 0 & A<=0.5) = 0.75;
image(X,Y,whitemat,'AlphaData',A);
end
% restack the objects
hl = findobj(hfig,'Type','line');
uistack(hl,'top');
%uistack(hn,'bottom');
% % add line at time = 0
% hold on; line([0 0],[min(Y) max(Y)],'Color','k','LineWidth',2);
hold off;
end
% pimp the topographical plot
for i = 1:length(ht)
% get data
X = get(ht(i),'XData');
Y = get(ht(i),'YData');
Z = get(ht(i),'CData');
% adjust X and Y to have centre at zero. This is necessary because the
% original plot was made using surface
X = X + 0.5/size(X,1);
Y = Y + 0.5/size(Y,1);
% create new figure if requested
if pimp < 0
if ~exist('hnfig','var')
hnfig = copyobj(hfig,0);
end
figure(hfig);
end
% re-plot data using contourf
set(hfig,'CurrentAxes',get(ht(i),'Parent'));
delete(ht(i));
hold on; %hold(ha(i),'on');
[C,hn] = contourf(X,Y,Z,stps,'LineStyle','none');
colormap(cmap);
% restack the objects
uistack(hn,'bottom');
end
% % continue working on new figure if requested
% if pimp < 0
% hfig = hnfig;
% end
% % make background white
% set(hfig,'Color','w');
if set_printing_properties
% set correct printing properties
set(hfig,'PaperType','<custom>');
%set(h,'PaperUnits','centimeters');
if strcmpi(get(hfig,'PaperUnits'),'centimeters')
set(hfig,'PaperSize',[20 15]);
set(hfig,'PaperPosition',[0 0 20 15]);
elseif strcmpi(get(hfig,'PaperUnits'),'inches')
set(hfig,'PaperSize',[8 6]);
set(hfig,'PaperPosition',[0 0 8 6]);
end
end
% set output
if nargout > 0
varargout = {hfig};
end