2D color or surface plot based on 3 vectors of data

24 ビュー (過去 30 日間)
Jordi Riba
Jordi Riba 2018 年 4 月 11 日
コメント済み: Jordi Riba 2018 年 4 月 12 日
I want to do a 2D plot based on 3 vectors of data (X,Y and Z) coming from rig results, in order to have some color surfaces between the points that shows the trend to where the values are increasing or decreasing. Ideally should contain also some iso-lines appart from the Colors. Not sure how to achieve it but I have seen it published.
The closest I could get to what I want was to use a simple scatter (X,Y Z) plot. But when I tried to generate surfaces between them by using the ‘peaks’ function then I had the problem that my X and Y plots are not strictly increasing or decreasing, and that there were some repeated values, so I could not use the function ‘contourf’.
Any help is more than welcome!

採用された回答

Pawel Jastrzebski
Pawel Jastrzebski 2018 年 4 月 11 日
編集済み: Pawel Jastrzebski 2018 年 4 月 11 日
How about this:
% interpolation data
% as in:
% https://uk.mathworks.com/help/matlab/ref/scatteredinterpolant.html?searchHighlight=scatteredInterpolant&s_tid=doc_srchtitle#responsive_offcanvas
F = scatteredInterpolant(datarig.X,datarig.Y,datarig.Z);
[xq,yq] = meshgrid(40:115,25:65);
F.Method = 'natural';
zq = F(xq,yq);
%colorbar data
limLow = min(datarig.Z);
limHi = max(datarig.Z);
c = linspace(limLow,limHi,length(datarig.Z));
figure;
scatter3(datarig.X,datarig.Y,datarig.Z,[],c);
caxis([limLow, limHi])
colorbar('Limits',[limLow, limHi]);
hold on;
contourf(xq,yq,zq)
%surface(xq,yq,zq)
%view(90,90)
Output:
  4 件のコメント
Pawel Jastrzebski
Pawel Jastrzebski 2018 年 4 月 12 日
Plot only the:
figure;
contourf(xq,yq,zq)
And nothing else. I added the other plots to see how the interpolation really worked.
Jordi Riba
Jordi Riba 2018 年 4 月 12 日
Thanks Pawel!!! it works really well !!! Cheers! Jordi

サインインしてコメントする。

その他の回答 (1 件)

Pawel Jastrzebski
Pawel Jastrzebski 2018 年 4 月 11 日
In order to be able to use contour plot, your Z data need to be of X*Y size. What you can do is the following:
% C is a matrix of colours assigned to your data
% Color will get assigned based on the user specified condition
% Simple example with 3 colors RGB
% Red = [1 0 0]
% Green = [0 1 0]
% Blue = [0 0 1]
c = zeros(size(datarig,1),3);
cond1 = datarig.Z<=1.0e+09 *1;
c(cond1,1) = 1;
cond2 = (datarig.Z>1.0e+09 *1) & (datarig.Z<=1.0e+09 *1.15);
c(cond2,2) = 1;
cond3 = ~(cond1+cond2);
c(cond3,3) = 1;
% point size
s = 25;
figure
scatter3(datarig.X,datarig.Y,datarig.Z,s,c)
view(90,90)
To obtain something like:
  1 件のコメント
Jordi Riba
Jordi Riba 2018 年 4 月 11 日
Thanks Pawel, but this is not what I wanted. To get something similar I could just simple use a scatter, and I get what is shown on the attachment. I want to create extrapolated surfaces with iso-lines.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by