Plotting 2D XY values as a 3D radial contour plot
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I want to plot XY values, where X represents the values accross a radius (0 is the center of the distrbution) and Y represents the colors of a heatmap (like a Gaussian distribution). I want it to look like the image attached. Can anyone please tell me how to do this? Thanks!
채택된 답변
Mathieu NOE
2022년 1월 11일
hello
my 2 cents suggestion
clc
clearvars
data = importdata('data.txt');
x = data.data(:,1);
n = 200;
r = linspace(min(x),max(x),n);
z = data.data(:,2);
zz = interp1(x,z,r);
figure, hold on
axis square
for ci = 1:200
theta = rand(n,1)*2*pi;
XX = r'.*cos(theta);
YY = r'.*sin(theta);
scatter(XX,YY,5,log10(zz),'filled')
end
% Color maps.
% parula - Blue-green-orange-yellow color map
% hsv - Hue-saturation-value color map.
% hot - Black-red-yellow-white color map.
% gray - Linear gray-scale color map.
% bone - Gray-scale with tinge of blue color map.
% copper - Linear copper-tone color map.
% pink - Pastel shades of pink color map.
% white - All white color map.
% flag - Alternating red, white, blue, and black color map.
% lines - Color map with the line colors.
% colorcube - Enhanced color-cube color map.
% vga - Windows colormap for 16 colors.
% jet - Variant of HSV.
% prism - Prism color map.
% cool - Shades of cyan and magenta color map.
% autumn - Shades of red and yellow color map.
% spring - Shades of magenta and yellow color map.
% winter - Shades of blue and green color map.
% summer - Shades of green and yellow color map.
colormap('autumn');
댓글 수: 7
Aero Descerazes
2022년 1월 11일
편집: Aero Descerazes
2022년 1월 13일
@Mathieu NOE Thank you very much for your response!
I have two questions:
- The colorbar doesn't seem to be accurate. At the center (x=0), the y-value is 197 and the lowest y-value is 5. But the colorbar seems to be on a different scale. Is there a way to fix this?
- I realized you used a scatterplot but the points seem to be scattered leaving white spaces in between. Is there a way to smoothen it in the periphery (like the center)?
Thanks again!
Mathieu NOE
2022년 1월 12일
편집: Mathieu NOE
2022년 1월 12일
hello again
1/ this is due to the fact that I wanted the center peak to be flatten , so I decided to plot the log10 of the data
scatter(XX,YY,5,log10(zz),'filled')
remove the log10 and the colorbar range will be according to your input data
scatter(XX,YY,5,zz,'filled')
2/ I supposed from the picture example that the result should be a scatter plot, with dots a bit random distributed inside the circle ; otherwise we can do a "continuous" surface plot (with surf)
what is your preference ?
here an alternative with surf
my "r" correspond to the first column of your data
my "z" correspond to the second column of your data
clc
clearvars
data = importdata('data.txt');
r = data.data(:,1);
z = data.data(:,2);
figure(1),
n = 50;
for ci = 1:n
theta = (ci-1)/(n-1)*2*pi;
XX(:,ci) = r'.*cos(theta);
YY(:,ci) = r'.*sin(theta);
zz(:,ci) = z;
end
s = surf(XX,YY,zz);
view(2);
% view(2) sets the default 2-D view, AZ = 0, EL = 90.
% view(3) sets the default 3-D view, AZ = -37.5, EL = 30.
s.EdgeColor = 'none'; % hide the edges by setting the EdgeColor property.
axis square
% Color maps.
% parula - Blue-green-orange-yellow color map
% hsv - Hue-saturation-value color map.
% hot - Black-red-yellow-white color map.
% gray - Linear gray-scale color map.
% bone - Gray-scale with tinge of blue color map.
% copper - Linear copper-tone color map.
% pink - Pastel shades of pink color map.
% white - All white color map.
% flag - Alternating red, white, blue, and black color map.
% lines - Color map with the line colors.
% colorcube - Enhanced color-cube color map.
% vga - Windows colormap for 16 colors.
% jet - Variant of HSV.
% prism - Prism color map.
% cool - Shades of cyan and magenta color map.
% autumn - Shades of red and yellow color map.
% spring - Shades of magenta and yellow color map.
% winter - Shades of blue and green color map.
% summer - Shades of green and yellow color map.
colormap('autumn');
colorbar('vert');
Aero Descerazes
2022년 1월 13일
편집: Aero Descerazes
2022년 1월 13일
Just need your help in one last thing - when I try to plot a different data, the plot is not as smooth (see below). I tried using interp2 to smoothen the surf but it is giving me an error. "Input grid is not a valid MESHGRID."
How do I overcome this? Thanks again.
Hello
if your data lack a bit of resolution, you can do some interpolation at the evry beginning (added this in the code below)
clc
clearvars
data = importdata('data.txt');
x = data.data(:,1);
% resample the data (interpolation) for a better resolution
r = linspace(min(x),max(x),100);
z = data.data(:,2);
z = interp1(x,z,r);
figure(1),
n = 100;
for ci = 1:n
theta = (ci-1)/(n-1)*2*pi;
XX(:,ci) = r'.*cos(theta);
YY(:,ci) = r'.*sin(theta);
zz(:,ci) = z(:);
end
s = surf(XX,YY,zz);
view(2);
% view(2) sets the default 2-D view, AZ = 0, EL = 90.
% view(3) sets the default 3-D view, AZ = -37.5, EL = 30.
s.EdgeColor = 'none'; % hide the edges by setting the EdgeColor property.
axis square
% Color maps.
% parula - Blue-green-orange-yellow color map
% hsv - Hue-saturation-value color map.
% hot - Black-red-yellow-white color map.
% gray - Linear gray-scale color map.
% bone - Gray-scale with tinge of blue color map.
% copper - Linear copper-tone color map.
% pink - Pastel shades of pink color map.
% white - All white color map.
% flag - Alternating red, white, blue, and black color map.
% lines - Color map with the line colors.
% colorcube - Enhanced color-cube color map.
% vga - Windows colormap for 16 colors.
% jet - Variant of HSV.
% prism - Prism color map.
% cool - Shades of cyan and magenta color map.
% autumn - Shades of red and yellow color map.
% spring - Shades of magenta and yellow color map.
% winter - Shades of blue and green color map.
% summer - Shades of green and yellow color map.
colormap('autumn');
colorbar('vert');
@Mathieu NOE This is perfect! Thank you so much for your help!
my pleasure !
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
