How to plot pixels on the figure when I have coordinates of the center of each pixel

15 views (last 30 days)
Hello,
I have the coordinates of the center of 93 0.5x0.5 pixels.
I want to plot them like this picture:
Here is my data which contains latitude, longitude, and also value.
Any suggestion or advice is highly appreciated.

Accepted Answer

Ameer Hamza
Ameer Hamza on 5 May 2020
Edited: Ameer Hamza on 5 May 2020
Try scatteredInterpolant()
x = points{:,1};
y = points{:,2};
z = points{:,3};
interp_model = scatteredInterpolant(x, y, z);
xg = linspace(min(x), max(x), 100);
yg = linspace(min(y), max(y), 100);
[Xg, Yg] = meshgrid(xg, yg);
Zg = interp_model(Xg, Yg);
pcolor(Xg, Yg, Zg)
or you can add
shading interp
after pcolor() to get a smooth surface
  19 Comments
BN
BN on 7 May 2020
Dear Ameer Hamza,
I'm sorry but I have another problem here.
When I start comparing the figure from the first model and second model's pixels I found that the values of the color bar are different while the colors of pixels are similar. For example please look at these two pictures, the first one generated for the first model and the second one generated for the next model:
I have a yellow color in both but in the first one, it indicates values near 350 while in second figure yellow pixels show values about 140.
In order to compare, do you think there is any way to make color stable in both?
For example, yellow color in all figures of models shows near 300 values.
Here is an example and I have to compare more than 20 models.
Thank you again for your help.
Ameer Hamza
Ameer Hamza on 7 May 2020
Yes, It is possible, but that will make the points in some figures to be very similar. For example, If you set the limits of the color axis from 0 to 400 for all figures, then if the points lie between [127 130], they will have a very similar color. Try following code. I set the limits of color axis as [0 400]
s = shaperead('country_Boundary.shp');
%%
mapshow(s)
hold on
axis equal
ax = gca;
xL = ax.XLim;
yL = ax.YLim;
%%
load data
rect_x = [-0.25 -0.25 0.25 0.25];
rect_y = [0.25 -0.25 -0.25 0.25];
x = points{:,1};
y = points{:,2};
z = points{:,3};
num_colors = 200;
clrs = summer(num_colors);
zlim = [0 400];
clr_val = @(z) clrs(ceil(interp1(zlim, [0 1], z)*num_colors), :);
for i=1:numel(x)
p(i) = patch(rect_x + x(i), rect_y + y(i), ...
clr_val(z(i)), ...
'EdgeColor', 'none');
end
ax.XLim = xL;
ax.YLim = yL;
colorbar
colormap(summer)
caxis(zlim)

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!