contourf with fixed colormap

2 ビュー (過去 30 日間)
gugum gumbira
gugum gumbira 2016 年 5 月 3 日
回答済み: Mike Garrity 2016 年 5 月 3 日
Dear all,
I have cell data contain wave high penetration for illustration purpose, I plan to create a GIF file.
It seem working well in simulate the wave penetration but the colour always changing every loop.
How to make the colormap unchanged every loop ? ?
Here I send the script that I use
V = 60:60:2340;
C = cell(size(V));
for k = 1:numel(V)
filename = sprintf('ZA00%04d.TXT', V(k));
C{k} = load(filename,'AAAA');
end
figure(1)
filename = 'testnew51.gif';
C = cell2mat(C);
iwant1 = (1:708:27612) ;
iwant2 = (708:708:27612) ;
r = zeros(256, 1);
g = zeros(256, 1);
b = zeros(256, 1);
Z1=min(C(:));
Z2=max(C(:));
index999 = round((-9.9900 - Z1)/(Z2 - Z1) * 256)
r(1:index999) = linspace(0, 1, index999);
g(1:index999) = linspace(0, 1, index999);
b(1:index999) = 1;
r(index999:end) = 1;
255-index999
g(index999:end) = linspace(1, 0, 257-index999);
b(index999:end) = linspace(1, 0, 257-index999);
cmap = [r,g,b]; % jet(256);
colormap(cmap);
colorbar;
caxis([Z1, Z2]);
% [r c] = find(C==-9.9900);
%indices = find(C==-9.9900);
%C(indices)=0;
%Zlimit=[Z1 Z2];
%demcmap(Zlimit)
% colormapeditor
%[cmap]=buildcmap('bwr');
%colormap(cmap) % set colormap disini
%caxis ([-10 10])
for n = 1:length(iwant1) % looping sepanjang kolom1
contourf(flipud(flipud(flipud(C(:,iwant1(n):iwant2(n)))))) ; % Plot contour sesuai kolom
drawnow % update gambar per frame
frame = getframe(1); % mendapatkan gambar setiap frame
%F = getframe(gcf);
%image(F.cdata)
im = frame2im(frame); % convert frame ke image
[imind,cm] = rgb2ind(im,256); % convert RGB image ke indexceed image
if n == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf); % image ke file grafik
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end

回答 (1 件)

Mike Garrity
Mike Garrity 2016 年 5 月 3 日
Try uncommenting the call to caxis and moving it after the call to contourf. It needs to be after the call to contourf because that (like most plotting functions) resets the CLim of the axes.

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by