Transparent background for figures to make a movie

Hey,
I have some cloud data (ice optical depths) to plot and make a movie that shows the evolution of clouds over time. I managed to make a movie with the cloud data, but now I want to include the topography map as the transparent background. In the movie it should look like that clouds are moving over the topography map. I tried several methods and failed. The topography map is attached. Cloud data are in an array with dimensions (120,120,365). The dimensions represent, (latitide, longitude, time). So each cloud map (120X120) should plot on the attached picture with a 0.01 time interval. I just need to know how to include the map as the transparent background. Does anyone think this is possible? I have included the movie I made and some of the cloud data (120X120X40). Any help will be appreciated.
Also, the clouds should be in grey color scale and the topography map can be modified in order to fit the cloud data.
Below is the code I used to make the movie.
figure(1);
vidfile = VideoWriter('Olympus10.mp4','MPEG-4');
% vidfile.FrameRate = 60;
open(vidfile);
for ind = 1:365%(change 365 to 40 to run with the data I uploaded)
imagesc(H(:,:,ind));
colormap(gray);
c=[0.01 1];
h=imagesc(squeeze(H(:,:,ind)),c);
h1 = colorbar;
stng='F';
title(h1,stng);
h1 = colorbar;
fclose all
grid on
ax=gca;
ax.GridColor = 'w';
ax.GridLineStyle='--';
ax.GridAlpha = 0.5;
ax.Layer='top';
set(gca,'ytick',[0:24:120],'fontsize',18);
yticklabels(27:-3:12);
set(gca,'xtick',[0:24:120],'fontsize',18);
xticklabels(-141:3:-126);
xlabel('East Longitude (\circ)')
ylabel('Latitude (\circ)')
s = num2str(ind);
t = strcat(s);
title(t);
drawnow;
pause(0.01);
F(ind) = getframe(gcf);
writeVideo(vidfile,F(ind));
end
close(vidfile);

 Risposta accettata

Try using function pcolor so that you can adjust the FaceAlpha value.
I = imread('image.png');
[Ny,Nx,Nz]=size(H);
[X,Y]=meshgrid(1:Nx,1:Ny);
figure(1)
ax = gca;
imagesc(ax,imresize(I,[Ny Nx]));
hold(ax,'on');
for ind = 1:Nz%(change 365 to 40 to run with the data I uploaded)
p = pcolor(ax,X,Y,H(:,:,ind));
p.FaceAlpha=0.6; % You may adjust this value
p.EdgeColor = 'none';
colormap(ax,'gray');
c=[0.01 1];
h1 = colorbar;
h1.Limits = [0 1];
stng='F';
title(h1,stng);
%fclose all
grid on
ax.GridColor = 'w';
ax.GridLineStyle='--';
ax.GridAlpha = 0.5;
ax.Layer='top';
set(gca,'ytick',[0:24:120],'fontsize',18);
yticklabels(27:-3:12);
set(gca,'xtick',[0:24:120],'fontsize',18);
xticklabels(-141:3:-126);
xlabel('East Longitude (\circ)')
ylabel('Latitude (\circ)')
s = num2str(ind);
t = strcat(s);
title(t);
drawnow;
pause(0.1);
F(ind) = getframe(gcf);
delete(p)
writeVideo(vidfile,F(ind));
end

8 Commenti

This is amazing. Thank you. You saved me a lot of time.
There is one problem though. The scale of the color bar changes in each frame. Is there a way to keep the colorbar constant in all the figures?
Thank you.
Did you added the following line to fix the colorbar limits?
Sorry forgot to mention on my previous reply.
h1 = colorbar;
h1.Limits = [0 1];
Yes. I did. But to no avail.
Strange, I also encountered the same issue but can be fixed by setting the limit.
Attached is the movie from my testing.
I may need more time to think about it since I am not available at the moment.
I fixed it. Change the following commented lines.
% h1 = colorbar;
% h1.Limits = [0 1];
% stng='F';
% title(h1,stng);
colorbar;
caxis([0.1 1]);
stng='F';
title(stng);
Great! Also learn the solution from you.
Master learned from the student!! :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by