Colour plot vs Time on a circle

5 vues (au cours des 30 derniers jours)
Sankar Ram T
Sankar Ram T le 25 Mai 2020
Modifié(e) : Sankar Ram T le 30 Mai 2020
I have temp vs time data for 100 points along a circle.
I would like create a small animation of the temp vs time basedon colour of the circle.
(If not a circle I would atleast like to try it along a line. )
Is it possible somehow?
A sample/Example would be like this
This has 6 frames, with the color representing the temperature and frames representing the passage of time.
Here it is made as a contiuous diagram, with smooth gradients. If it is not possible, is it possible as discreet sections of a circle.
  4 commentaires
darova
darova le 26 Mai 2020
Please attach the data
Sankar Ram T
Sankar Ram T le 26 Mai 2020
Coloum 1 is Time (Sec)
Rest are temperatures of 20 Sectors

Connectez-vous pour commenter.

Réponses (1)

Kelly Kearney
Kelly Kearney le 26 Mai 2020
It's not clear to me whether you've already created the circle plots in Matlab, or if you just sketched out your desire outcome.
If you haven't plotted them yet, I think using a simple patch is the easiest way to achieve that look. To animate, it depends on whether you just want to animate on screen or export to something like a gif. The example below shows the former.
% Some example data
t = linspace(0,1,100)'; % time coordinate, normalized
data = rand(100,3); % three time steps of random data
% Use patch to plot the circle
th = 2*pi*t;
rmin = 0.8; % inner radius
rmax = 1; % outer radius
xouter = rmax.*cos(th);
xinner = rmin.*cos(th);
youter = rmax.*sin(th);
yinner = rmin.*sin(th);
x = [xouter; xinner(end:-1:1); xouter(1)];
y = [youter; yinner(end:-1:1); youter(1)];
c = [data; data(end:-1:1,:); data(1,:)];
axes
p = patch(x,y,c(:,1));
axis equal;
set(gca, 'visible', 'off');
set(p, 'edgecolor', 'none');
% Loop over to animate
for it = 2:size(data,2)
pause(1);
set(p, 'cdata', c(:,it));
end
  3 commentaires
Kelly Kearney
Kelly Kearney le 29 Mai 2020
Here's the example again, this time with your data and more comments:
% Your data
tmp = readtable('~/Downloads/10Sec - Copy.xls');
data = table2array(tmp(:,2:end))'; % sector x time array
sector = 1:size(data,1); % sector, 1,2,...20
% Step 1: upsample your data. This isn't strictly necessary but will allow
% your ring to look more like a circle than a 20-gon
secup = linspace(1,20,100)';
data = interp1(sector, data, secup); % new higher-res sector x time array
% Step 2: Calculate x- and y-coordinates of the ring
secnorm = (secup - min(secup))./(max(secup)-min(secup)); % normalize sector...
th = 2*pi*secnorm; % ... and then convert to angle between 0 and 2*pi
rmin = 0.8; % inner radius
rmax = 1; % outer radius
xouter = rmax.*cos(th); % coordinates of outer ring (counterclockwise from right)
xinner = rmin.*cos(th);
youter = rmax.*sin(th); % coordinates of inner ring (counterclockwise from right)
yinner = rmin.*sin(th);
% ... to draw the ring, connect the outer circle counterclockwise, then the
% inner circle clockwise, and then back to the first point of the outer
% circle.
x = [xouter; xinner(end:-1:1); xouter(1)]; % ring x coords
y = [youter; yinner(end:-1:1); youter(1)]; % ring y coords
c = [data; data(end:-1:1,:); data(1,:)]; % color data corresponding to each vertex
% Prepare time label (just for reference)
tstr = cellstr(num2str(tmp.Time, '%6.4f')); % # time x 1 cell array
% Step 3: Plot using the color data for the first time step
axes;
p = patch(x,y,c(:,1)); % plot patch
axis equal; % set aspect ratio equal
set(gca, 'visible', 'off', 'clim', [0 1505]); % hide the axis box and ...
% set the color limits to match the data
t = text(0, 1.1, tstr{1}, 'horiz', 'center'); % Add a text label with the time
set(p, 'edgecolor', 'none'); % hide the edges of the patch
colorbar('west'); % add a colorbar
% Step: Loop to animate, changing color data and time label
for it = 2:size(data,2)
pause(0.01);
set(p, 'cdata', c(:,it));
set(t, 'string', tstr{it});
end
Sankar Ram T
Sankar Ram T le 29 Mai 2020
Modifié(e) : Sankar Ram T le 30 Mai 2020
By the time I undersood your pevious code, you made a improved version. 👍👍
I had worked around the previos code to plot my data. I found 2 bugs.
1) The top of the image has a 'patch'. The colours are not uniform there. What would cause that?
(May be the vertices on outer and inner are not lining up corretly???)
2)There is a jump in colour towards the right side of circle. I believe it is the start of the patch. Any way to smoothen this out?
I will go through the 2nd set of code, and get back. THANK YOU for the prompt reply.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by