Is it possible to generate a pot that contains all column temperature data from T0 to T10?

2 views (last 30 days)
Hello,
Can someone help me with that?
The attached data below have X and Y coordinates and temperature from T0 to T10. I was only able to generate a plot for T0. When I tried to plot all temperature variables using the same code, it didn't work.
Also, is it possible to get rid of the yellow background color?
Thank you!
Here are the code I use:
filename='T.csv';
df = csvread(filename,1,0);%skip 1 header lines
X_df=df(:,2);
Y_df=df(:,3);
T_df=df(:,6); % when I tried T_df = df(:, 6:end) it gave an error for line 11
%create grid
[x,~,xi]=unique(X_df);
[y,~,yi]=unique(Y_df);
subs=[xi yi];
val=T_df;
M=accumarray(subs,val);
[X,Y]=ndgrid(x,y);
%create plot
figure(1),clf(1)
surf(X,Y,M)
view(0,90),xlabel('x(ft)'),ylabel('y(ft)'), title("EB Morning Run for T0")
colorbar
shading interp

Accepted Answer

Walter Roberson
Walter Roberson on 30 Jul 2023
Edited: Walter Roberson on 30 Jul 2023
When you surf() without using caxis() or clim() then the lowest value is mapped to the first color in your color map, and the highest value is mapped to the last color in your color map.
According to your colorbar, the yellow corresponds to 0 and that is the maximum. So the values you are accumulating are negative. But when you called accumarray() you did not specify an initial value for the bins, so any location that did not have a matching entry in the data is going to be initialized to 0. Therefore the "empty" parts of your graph are going to come out with (in this case) the last color in your colormap. With the default colormap that turns out as yellow.
You could create a colormap by copying an existing map and changing the yellow to some other specific color, but the result would be a background of that specific color.
What you probably want to do is to use the 5-parameter version of accumarray(), specifying NaN as the "fill value", so that places with no data come out as NaN in the array. surf() does not draw anything for NaN values.
... Though it is a little more complicated than that. Surf() takes the supplied values as being the vertices and assumes that it needs to interpolate face colors according to the four vertices of the face. If even one of the vertices is NaN value then the interpolation is going to turn out NaN -- so a single NaN "poisons" several faces, not just a single face.
Sometimes instead of surf() what you want to do is either imagesc() (rectangular grid coordinates only) or else warp (does not have to be rectangular coordinates.)
By the way, there is a "shortcut" for surf() followed by view(0,90): you can use pcolor instead, which will create a surface and call view() internally. But pcolor() has exactly the same behaviour for NaN. When you are trying to display grids of data with one face for each value in the array, you should probably not be using surf() or pcolor()
  9 Comments
Walter Roberson
Walter Roberson on 31 Jul 2023
The outputs here on MATLAB Answers are too small to be useful, but they will look a bit better on your system. Not fabulous, but better.
You are trying to generate surface plot for scattered values with the assumed background (zeros) being much further away than the difference between minimum and maximum values, You cannot get a reasonable surface plot with that, not without at the very least hiding the background. And even then the fact that the data is scattered makes the surface plot of questionable utility.
I have a suspicion that you might be wanting to consider the scattered data as local peaks (or valleys) and that you want to effectively drape a surface over it. If that is the case, you would proceed differently, such as by using griddedInterpolant or scatteredInterpolant sampling uniformly over your surface (instead of using irregularly spaced rectangular blobs like you are now.)
filename='T.csv';
df = csvread(filename,1,0);%skip 1 header lines
X_df=df(:,2);
Y_df=df(:,3);
%create grid
[x,~,xi]=unique(X_df);
[y,~,yi]=unique(Y_df);
subs=[xi yi];
tiledlayout('flow');
for col = 6 : size(df,2)
T_df=df(:,col);
val=T_df;
M = accumarray(subs, val, [], [], nan);
[X,Y]=ndgrid(x,y);
%create plot
nexttile();
pcolor(X, Y, M);
xlabel('x(ft)')
ylabel('y(ft)')
title("EB Morning Run for T" + (col-6))
colorbar
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!