Create a 2D plot with irregular axes
9 views (last 30 days)
Show older comments
I have a dataset with associated x and y coordinates, but the coordinates for both axes are not at regular intervals. Is there a way to make a map (ideally 2D but I would accept 3D) that shows these results - the values represented by colour - at their coordinates (akin to imagsc)?
0 Comments
Answers (2)
Star Strider
on 2 May 2025
The plot function does not care if the data are not regularly sampled. It wil plot them appropriately regardless.
Example —
t = sort(rand(1,100));
s = sin(5*pi*t);
figure
plot(t, s, '.-')
grid
axis('padded')
sp = s;
sp(end) = NaN;
c = sp;
figure
patch(t,s,c, EdgeColor='interp',Marker='s',MarkerFaceColor='flat')
grid
axis('padded')
colormap(turbo)
I am not certain what you want.
.
3 Comments
Star Strider
on 5 May 2025
I am not certain what the image is, or what it represents.
Try something like this —
imshow(imread('TT3.png'))
x = randn(1000,1);
y = randn(1000,1);
figure
histogram2(x, y, 50, FaceColor='flat')
colormap(turbo)
% axis('equal')
axis('square')
view(0,90)
Make appropriate changes to get the result you want.
.
Walter Roberson
on 2 May 2025
pointsize = 20;
scatter(x, y, pointsize, Dataset(:))
This will produce colored round dots at the given locations.
Producing square or rectangular dots would be more work.
2 Comments
Walter Roberson
on 3 May 2025
Ah, I guess you can specify square markers for scatter() if you need to plot squares.
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!