2d density map in non rectangular region

조회 수: 9 (최근 30일)
Tiago
Tiago 2025년 11월 18일 15:34
답변: Star Strider 2025년 11월 18일 16:47
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');

답변 (1개)

Star Strider
Star Strider 2025년 11월 18일 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')
.

카테고리

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

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by