Controu plot from matlab table
이전 댓글 표시
I have a table with values extracted from a csv I want to make a contour plot from.
Let's use this table as an example
tdata.x = [1;2;1;2];
tdata.y = [3;3;4;4];
tdata.z = randn(4,1);
tdata=struct2table(tdata);
>> tdata
tdata =
4×3 table
x y z
_ _ _______
1 3 0.53767
2 3 1.8339
1 4 -2.2588
2 4 0.86217
I would like to pivot this such that I can use it for plotting a contour, so in principle I want a 2x2 z matrix where rows/columns are given by y and x respectively, something in this direction:
x 1 2
y
3 0.53767 1.8339
4 -2.2588 0.86217
답변 (1개)
KSSV
2021년 3월 18일
x = T.x ;
y = T.y ;
z = T.z ;
nx = length(unique(x)) ;
ny = length(unique(y)) ;
X = reshape(x,nx,ny) ;
Y = reshape(y,nx,ny) ;
Z = reshape(z,nx,ny) ;
contour(X,Y,Z)
댓글 수: 9
Morten Nissov
2021년 4월 8일
KSSV
2021년 4월 8일
file = 'EMAG2_amsterdam.csv';
map = readtable(file);
lon = map.lon;
lat = map.lat;
z = map.upCont;
m = 100 ; n = 100 ;
x = linspace(min(lon),max(lon),m) ;
y = linspace(min(lat),max(lat),n) ;
[X,Y] = meshgrid(x,y) ;
Z = griddata(lon,lat,z,X,Y) ;
figure(1)
contourf(X,Y,Z)
xlabel('longitude')
ylabel('latitude')

Morten Nissov
2021년 4월 8일
KSSV
2021년 4월 8일
Yes..use the present given code.
Morten Nissov
2021년 4월 8일
편집: Morten Nissov
2021년 4월 8일
KSSV
2021년 4월 8일
That should work...but the data arrangment should be considered.
Morten Nissov
2021년 4월 8일
KSSV
2021년 4월 9일
The gird looks fine when you use
scatter(X(:),Y(:),[],Z(:),'.')
Show me the PAndas code which worked for you.
Morten Nissov
2021년 4월 9일
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!