pcolor issue with irregular grid
15 ビュー (過去 30 日間)
古いコメントを表示
I have been spending way too much time and would appreciate your insight and comments.
I am using “pcolor” to plot my data on an irregular grid (regularizing it is not an option).
-when I plot the even rows of my X, Y, and data the figure is what I expect (figure 1).
-when I plot the odd rows of my X, Y, and data the figure is what I expect (figure 2).
-when I plot the all rows of my X, Y, and data the figure is NOT what I expect (figure 3).
**figure 3 should be similar to figures 1&2 (basically those 2 superimposed).
the data, X, and Y are attched.
Thanks again.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/464300/image.png)
clear all; close all; clc
load('C:\Desktop\Test\X.mat');
load('C:\Desktop\Test\Y.mat');
load('C:\Desktop\Test\data.mat');
% replaceing zeros with NAN
X(X == 0) = NaN;
Y(Y == 0) = NaN;
data(data == 0) = NaN;
% choosing even rows
X1 = X(2:2:end,:);
Y1 = Y(2:2:end,:);
data1 = data(2:2:end,:);
% choosing odd rows
X2 = X(1:2:end,:);
Y2 = Y(1:2:end,:);
data2 = data(1:2:end,:);
figure(1)
h1 = pcolor(X1,Y1,data1);
set(h1,'edgecolor','none');
figure(2);
h2 = pcolor(X2,Y2,data2);
set(h2,'edgecolor','none');
figure(3);
h3 = pcolor(X,Y,data);
set(h3,'edgecolor','none');
2 件のコメント
Mathieu NOE
2020 年 12 月 20 日
hi
have to figure out why pcolor is doing that
with imagesc I don't have the problem
clear all; close all; clc
load('X.mat');
load('Y.mat');
load('data.mat');
% replaceing zeros with NAN
X(X == 0) = NaN;
Y(Y == 0) = NaN;
data(data == 0) = NaN;
% choosing even rows
X1 = X(2:2:end,:);
Y1 = Y(2:2:end,:);
data1 = data(2:2:end,:);
% choosing odd rows
X2 = X(1:2:end,:);
Y2 = Y(1:2:end,:);
data2 = data(1:2:end,:);
figure(1)
h1 = imagesc(data1);
% set(h1,'edgecolor','none');
figure(2);
h2 = imagesc(data2);
% set(h2,'edgecolor','none');
figure(3);
h3 = imagesc(data);
% set(h3,'edgecolor','none');
採用された回答
Walter Roberson
2020 年 12 月 20 日
surf(X(1:2:end,:), 'edgecolor', 'none')
and rotate it a bit, and you can see that the bulk of it is a single titled plane.
surf(X(2:2:end,:), 'edgecolor', 'none')
is likewise a single titled plane.
Now
surf(X, 'edgecolor', 'none')
and you will observe a thick wedge.
So although even X and odd X individually form consistent planes, when you take both together they do not form a single plane. When used as coordinates, pcolor would have to try to compensate.
Note: pcolor is surf() followed by view(2), together with some logic that sets the Z coordinates of the surf to all 0.
3 件のコメント
Walter Roberson
2020 年 12 月 21 日
load X
load Y
load data
X(X == 0) = NaN;
Y(Y == 0) = NaN;
data(data == 0) = NaN;
mask = ~(isnan(X) | isnan(Y) | isnan(data));
F = scatteredInterpolant(X(mask), Y(mask), data(mask));
%trim down to useful part of data
[~, idx] = max(X(:));
[R, C] = ind2sub(size(X), idx);
lastC = C-2; %some of the last couple of columns dip down
Xsub = X(:,1:lastC);
minx = min(Xsub, [], 'all');
maxx = max(Xsub, [], 'all');
Ysub = Y(:,1:lastC);
miny = min(Ysub, [], 'all');
maxy = max(Ysub, [], 'all');
xv = linspace(minx, maxx, lastC);
yv = linspace(miny, maxy, size(X,1));
[XG, YG] = ndgrid(xv, yv);
Z = F(XG, YG);
h = pcolor(XG, YG, Z);
h.EdgeColor = 'none';
In theory this takes all of the data into account. However, it interpolates data coordinates, and in theory it would work out something like taking the bottom (even-numbered) layer and shifting it to the left, and then merging the two sheets. The results look okay, but before using the [XG, YG, Z] data for serious analysis, you should think more about how the triangulation process works to make sure that you really are getting contributions from both half.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Geographic Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!