从3个向量创建轮廓图 [英] Create a contour plot from 3 vectors

查看:121
本文介绍了从3个向量创建轮廓图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据以下数据创建轮廓图:

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

我已将数据导入为3种不同的向量:pH,D和Tur

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)

我希望是这样的:

但是我得到了:

推荐答案

您需要 meshgrid 首先:

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);

或者另一种替代方法是对两者都使用 unique 排序并从pHD中删除冗余值,从而减小了meshgrid产生的矩阵的大小:

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:

这篇关于从3个向量创建轮廓图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆