I'm trying to create a contour plot from this data:
pH D Tur
5.10 3 79.18918919
5.50 6 92.97297297
5.00 0 50.09009009
5.00 6 90.36036036
5.10 9 91.08108108
5.10 12 89.18918919
5.10 15 83.6036036
5.00 18 91.26126126
5.00 21 81.26126126
5.00 24 90.99099099
5.00 27 91.44144144
5.00 30 90.45045045
6.00 0 43.42342342
5.64 3 81.8018018
5.50 9 92.16216216
5.50 0 44.68468468
5.40 12 92.34234234
5.50 15 92.25225225
5.50 18 91.62162162
5.50 21 90.81081081
5.50 24 91.8018018
5.50 27 92.52252252
5.50 30 90.36036036
6.10 3 81.98198198
6.00 6 93.51351351
6.00 9 94.77477477
6.10 12 95.04504505
6.00 15 94.68468468
5.90 18 94.05405405
6.00 21 94.68468468
6.00 24 94.41441441
6.00 27 93.69369369
6.00 30 94.5045045
6.50 0 41.08108108
6.50 3 76.03603604
6.50 6 87.92792793
6.60 9 94.32432432
6.50 12 94.77477477
6.50 15 94.32432432
6.50 18 94.95495495
6.50 21 94.41441441
6.40 24 93.33333333
6.40 27 94.41441441
6.40 30 94.14414414
7.00 0 41.17117117
7.00 3 61.71171171
6.90 6 84.05405405
6.90 9 89.72972973
6.90 12 90.81081081
6.90 15 91.53153153
6.90 18 91.44144144
6.86 21 91.53153153
6.86 24 91.98198198
6.86 27 90.81081081
6.90 30 92.79279279
7.44 3 65.85585586
7.50 6 79.72972973
7.50 0 59.00900901
7.50 9 81.35135135
7.50 12 79.00900901
7.50 15 81.98198198
7.50 18 83.69369369
7.50 21 81.17117117
7.50 24 80.09009009
7.30 27 89.63963964
7.50 30 81.98198198
I've imported the data as 3 different vectors: pH, D, and Tur
I created a mesh and griddata and plot the contour
[X Y]=meshgrid(pH,D);
Z=griddata(pH,D,Tur,X,Y);
contourf(X,Y,Z)
I was hoping something like that:
But I'm getting this:
You need to sort your inputs to meshgrid
first:
[X, Y] = meshgrid(sort(pH), sort(D));
Z = griddata(pH, D, Tur, X, Y);
contourf(X, Y, Z);
Or another alternative is to use unique
to both sort and remove redundant values from pH
and D
, reducing the size of the matrices produced by meshgrid
:
[X, Y] = meshgrid(unique(pH), unique(D));
Z = griddata(pH, D, Tur, X, Y);
contourf(X, Y, Z);
And both of the above options give the same graphical result:
来源:https://stackoverflow.com/questions/43030227/create-a-contour-plot-from-3-vectors