Why is my 3-D plot not showing all of the data from my table row?

조회 수: 14 (최근 30일)
LoroEE
LoroEE 2022년 5월 30일
댓글: Walter Roberson 2024년 11월 8일 4:37
The table is in the file attached. This is the code I used:
Q1 = tabela_viaveis_ordenada(1:height(tabela_viaveis_ordenada),:);
VarNames = tabela_viaveis_ordenada.Properties.VariableNames;
ax = Q1{:,7};
ay = Q1{:,6};
az = Q1{:,2};
% create a grid basis and then interpolate on the grid
n = 50;
x11 = linspace(min(ax),max(ax),n);
y11 = linspace(min(ay),max(ay),n);
z11 = griddata(ax,ay,az,x11',y11);
% plot it
surf(x11,y11,z11)
xlabel(VarNames{7})
ylabel(VarNames{6})
zlabel(VarNames{2})
The 3-D plot looks like this, Z axis is "custo_total" variable from second row:
The smallest value of Z is 63348.2 in the graph but 55688.7 on the table.
In other words, my 3-D plot seems to skip over some data so I can't actually find the points I want using the "Data Tips" thing.
Why?
  댓글 수: 2
KSSV
KSSV 2022년 5월 31일
Check your data, (ax,ay,az) forms different layers.
So, when you have used griddata, you got the avrage of the data you have provided.
That is why you have missed the minimum value.
LoroEE
LoroEE 2022년 5월 31일
So, according to your link, my data is in the surface, not the points? How do I show it on the graph then? I just want to show that the data in my table is on the graph somewhere. I don't understand what to do.
This code was adapted from another question and documentation, I don't understand it very well and don't know how layers work and how this is an issue.

댓글을 달려면 로그인하십시오.

답변 (1개)

Vidhi Agarwal
Vidhi Agarwal 2024년 11월 8일 3:44
While using “griddata” function, the minimum value plotted in the graph is the interpolated value. Depending on the interpolation method used, it can smooth out the data, potentially missing some of the original data points, especially if they are outliers or isolated.
By Directly plotting the original data points on top of the interpolated surface you can visually ensure that original data points, including the minimum are represented in the graph. By this it is ensured that you have a smooth representation of data, and an accurate display of minimum.
By adding the following lines of code to the existing one, the issue must get resolved:
% Overlay original data points for reference
hold on;
plot3(ax, ay, az, 'o', 'MarkerFaceColor', 'r', 'MarkerEdgeColor', 'k');
hold off;
Hope that helps!
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 11월 8일 4:37
With most of the interpolation methods, including the default interpolation method for griddata , if (x,y) pairs on input are unique, then querying at exactly (x,y) will give back exactly the z that was present immediately. That is, given unique input points, most of the interpolation methods do not smooth data when queried at the original input points.
However, for all of the interpolation methods, something has to happen if there are duplicate (x,y) pairs in the input. In such cases, griddata() takes the mean() of each of the input z for each unique (x,y) pairs.
It happened that @LoroEE input data included a number of cases of the same (x,y) with different z. Those locations were each averaged out, and that is the reason that the output did not include the minimum of the data.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by