2d density map in non rectangular region
9 views (last 30 days)
Show older comments

I want to make this graph but instead of discrete points i want it to be a smooth color gradient. How can i do this? Every solution i found so far works with meshgrid which is not so good for this geometry. Thanks!
Code to generate the graph in the picture:
data = load('data_Temperature_T.dat');
x = data(:,1);
y = data(:,2);
T = data(:,3);
figure;
scatter(x, y, 20, T, 'filled');
axis equal tight;
colorbar;
xlabel('x'); ylabel('y');
title('Temperature');
0 Comments
Answers (1)
Star Strider
on 18 Nov 2025 at 16:47
It would help to have your data, since I cannot reproduce those curves here.
Try something like this --
n = 50;
a = linspace(pi, pi/2, n);
r = linspace(4, 20, n)*0.01;
x = [0.02*cos(a); r.*cos(a)].';
y = [0.05*sin(a); r.*sin(a)].';
figure
plot(x, y)
axis('equal')
c = [linspace(0, 0.5, n); linspace(0, 0.5, n)].';
figure
patch([x(:,1); flip(x(:,2))], [y(:,1); flip(y(:,2))], [c(:,1); flip(c(:,2))])
axis('equal')
.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots 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!
