Controu plot from matlab table

8 visualizaciones (últimos 30 días)
Morten Nissov
Morten Nissov el 18 de Mzo. de 2021
Comentada: Morten Nissov el 9 de Abr. de 2021
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

Respuestas (1)

KSSV
KSSV el 18 de Mzo. de 2021
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 comentarios
KSSV
KSSV el 9 de Abr. de 2021
The gird looks fine when you use
scatter(X(:),Y(:),[],Z(:),'.')
Show me the PAndas code which worked for you.
Morten Nissov
Morten Nissov el 9 de Abr. de 2021
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('EMAG2_faaborg.csv')
df = df[['lat','lon','upCont']].pivot('lat','lon')
lon = df.columns.levels[1].values
lat = df.index.values
vals = df.values
X,Y = np.meshgrid(lon, lat)
then I can plot using
plt.contourf(X, Y, vals)

Iniciar sesión para comentar.

Categorías

Más información sobre Geographic Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by