How to create an animated plot of a temperature data with holding on each year?

조회 수: 7 (최근 30일)
Hi dear community,
I want to create an animated plot of a temperature data. I have 122 files of measured temperatures and I want to plot them like below animation with holding previous plot on a same figure.
Do you have any ideas?

채택된 답변

David K.
David K. 2019년 7월 30일
Alright lets see how much I can help with.
First off to gradient between colors I have a little way down below. I get the rgb values of the colors I want to fade between and create a linspace between them. The example I gave fades from green to red.
Xticklabels can let you show the months instead of numbers.
text allows you to place the year on the plot.
p1.Color(4) = .5 decreases the opacity of the old plots.
numF = 122;
Colors = [linspace(0,1,length(numF))', flipud(linspace(0,1,length(numF))'),zeros(length(numF),1)];
figure; hold on;
for n = 1:122
p1 = plot(xData(n,:),yData(n,:),'Color',Colors(n,:));
%p1.Color(4) = 1; % may need this, not certain
xlabel(''); ylabel(''); title('');
xticklabels({'Jan' 'Feb' 'Mar'})
t1 = text(7,0,num2str(YEAR)); % Change the first two values to place on the plot where you want it
drawnow
pause(.1) % variable pause for however long you want to show the plot
delete(t1); % Remove the old label
p1.Color(4) = .5; % Decrease Opacity of previous plots
end
Sadly I do not know how to make the gradient on the right side but I hope this can get you on your way!
  댓글 수: 2
Luna
Luna 2019년 8월 24일
Thank you for your answer. It definetely gave me an idea how to make it.
Only this line didn't work for me. Unfortunetely it does not decrease the opacity. Color property accepts only 1x3 vectors.
p1.Color(4) = .5; % Decrease Opacity of previous plots
David K.
David K. 2019년 8월 26일
Ah, from what I had looked up and tested (R2018b) it did work when I was creating it. Shame that it did not work for your build. I can't seem to find a different way to change opacity.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by