Skip to content

Commit 010cdc2

Browse files
committed
plot_field: use diverging cmap for real(E) components
1 parent 3b6a282 commit 010cdc2

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

CELES_MAIN.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
% plot near field
134134
figure('Name','Near-field cross-cut','NumberTitle','off');
135135
plot_field(gca,simul,'abs E','Total field')
136-
colorbar
137136
caxis([0,2])
138137

139138
% % export animated gif

src/plot/plot_field.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ function plot_field(ax,simulation,component,fieldType,GIFoutputname)
6464
E = simulation.output.initialField;
6565
end
6666

67+
cmap = interp1(1:3,[0 0 1; 1 1 1; 1 0 0],linspace(1,3,256)); % define a diverging colormap
68+
6769
switch lower(component)
6870
case 'real ex'
6971
fld = reshape(gather(E(:,1)), dims);
@@ -73,18 +75,11 @@ function plot_field(ax,simulation,component,fieldType,GIFoutputname)
7375
fld = reshape(gather(E(:,3)), dims);
7476
case 'abs e'
7577
fld = reshape(gather(sqrt(sum(abs(E).^2,2))), dims);
78+
cmap = parula(256); % use default (sequential) colormap for abs(E)
7679
end
7780

78-
if exist('GIFoutputname','var')
79-
t = linspace(0,2*pi,26); t(end) = []; % 25 frames
80-
cmap = interp1(1:3,[0 0 1; 1 1 1; 1 0 0],linspace(1,3,256-32));
81-
gifcmap = [cmap; gray(32)]; % add some grayscale colors for the gif colormap
82-
caxislim = [-max(abs(fld(:))), max(abs(fld(:)))];
83-
else
84-
t = 0;
85-
cmap = parula(256);
86-
caxislim = [0, max(abs(fld(:)))];
87-
end
81+
% define axis limits: lower limit should be 0 for abs(E) and -max(abs(E)) for real(Ei)
82+
caxislim = [-max(abs(fld(:)))*min(0, min(real(fld(:))))/min(real(fld(:))) , max(abs(fld(:)))];
8883

8984
fldPnts = reshape([simulation.output.fieldPoints(:,1), ...
9085
simulation.output.fieldPoints(:,2), ...
@@ -108,10 +103,15 @@ function plot_field(ax,simulation,component,fieldType,GIFoutputname)
108103
idx = find(dist<rArr); % find particles intersecting the plane
109104
rArr(idx) = sqrt(rArr(idx).^2 - dist(idx).^2); % overwrite radius of the intersection circle
110105

111-
if exist('GIFoutputname','var') % initialize imind array
106+
if exist('GIFoutputname','var')
107+
t = linspace(0,2*pi,26); t(end) = []; % 25 frames
108+
cmap = interp1(1:3,[0 0 1; 1 1 1; 1 0 0],linspace(1,3,256-32));
109+
gifcmap = [cmap; gray(32)]; % tweak gif colormap to add some grayscale colors
112110
f = getframe(gcf);
113-
imind = rgb2ind(f.cdata,gifcmap,'nodither');
111+
imind = rgb2ind(f.cdata,gifcmap,'nodither'); % initialize imind array
114112
imind(1,1,1,numel(t)) = 0;
113+
else % no gif to be created
114+
t = 0;
115115
end
116116

117117
for ti=1:numel(t)

0 commit comments

Comments
 (0)