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');
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);
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;
g(index999:end) = linspace(1, 0, 257-index999);
b(index999:end) = linspace(1, 0, 257-index999);
cmap = [r,g,b]; % jet(256);
caxis([Z1, Z2]);
% [r c] = find(C==-9.9900);
%indices = find(C==-9.9900);
%Zlimit=[Z1 Z2];
% colormapeditor
%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);
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

답변 (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 CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by