从3个向量创建等高线图

时间:2017-03-26 14:46:58

标签: matlab plot contourf

我正在尝试根据这些数据创建等高线图:

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

我将数据导入为3种不同的载体:pH,D和Tur

我创建了一个网格和网格数据并绘制了轮廓

[X Y]=meshgrid(pH,D);
Z=griddata(pH,D,Tur,X,Y);
contourf(X,Y,Z)

我希望有类似的东西:

Hopped plot

但我得到了这个:

Ugly plot

1 个答案:

答案 0 :(得分:3)

首先需要sort meshgridunique的输入:

[X, Y] = meshgrid(sort(pH), sort(D));
Z = griddata(pH, D, Tur, X, Y);
contourf(X, Y, Z);

或另一种方法是使用enter image description herepHD中的冗余值进行排序和删除,从而减少meshgrid生成的矩阵的大小:

[X, Y] = meshgrid(unique(pH), unique(D));
Z = griddata(pH, D, Tur, X, Y);
contourf(X, Y, Z);

以上两个选项都给出了相同的图形结果:

{{3}}