make a contour plot with dates on x axis, time on y axis and fog concentration as z values.
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
shravani banerjee
el 27 de Sept. de 2018
Comentada: Toni
el 13 de Mzo. de 2023
I need to make a contour plot based on the calculated total fog. I am unable to do so as I am new to MATLAB. Hope Someone can help me.For reference I am attaching a sample of my data. Thanks
4 comentarios
dpb
el 28 de Sept. de 2018
Will need to use NaN to infill I think to get a regular grid; I imported the file as table to 'spearmint some.
contour may also require using datenum rather than datetime for the date/time axes; it is one of the specialty plotting routines not yet (R2017b) gotten to with aliased version for the new class.
Toni
el 13 de Mzo. de 2023
For contour plots, x and y axis ticks labels can be modifed via xticklabels and yticklabels. Reshape in the answer below did not work due to missing data, but code below avoids that by inserting Nan where data is missing.
filename = '1st-10th_dec.csv'
data=readtable(filename)
data.Date = datetime(data.Date,'inputformat','dd-MM-yyyy');
data.Time = duration(data.Time,'inputformat','hh:mm');
date = unique(data.Date);
t = unique(data.Time);
for i=1:length(date)
for j=1:length(t)
index = find(data.Date == date(i) & data.Time == t(j));
if ~isempty(index)
v(j,i) = data.Fog___(index);
else
v(j,i) = NaN;
end
end
end
figure
contourf(datenum(date),datenum(t),v)
xticks(datenum(date))
xticklabels(string(date))
t_ticks = [min(t):hours(2):max(t)];
yticks(datenum(t_ticks))
yticklabels(string(t_ticks))
Respuesta aceptada
jonas
el 28 de Sept. de 2018
Editada: jonas
el 28 de Sept. de 2018
As dbp said, contour is not compatible with datetime format. Here's an example with surf, which is quite similar.
data=readtable('1st-10th_dec.csv')
date=datetime(data{:,1},'inputformat','dd-MM-yyyy');
t=duration(data{:,2},'inputformat','hh:mm');
v=data{:,3};
[~,udate]=findgroups(date);
[~,ut]=findgroups(t);
v=reshape(v,numel(ut),numel(udate))
surf(udate,ut,v)
view([0 90])
and here is the example with contour,
data=readtable('1st-10th_dec.csv')
v=data{:,3};
date=nan(size(data,1),1)
t=nan(size(data,1),1)
date(~isnan(v))=datenum(data{~isnan(v),1},'dd-mm-yyyy')
t(~isnan(v))=datenum(data{~isnan(v),2},'HH:MM')
[~,udate]=findgroups(date);
[~,ut]=findgroups(t);
v=reshape(v,numel(ut),numel(udate))
contour(udate,ut,v)
datetick('x','dd/mm','keeplimits','keepticks')
datetick('y','hh:mm','keeplimits','keepticks')
The resulting plot is quite ugly. This is however easy to fix by interpolation.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!