plot 2D contours
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I need help to plot 2D contours as shown in the figure for mutiple files. I am attaching my code and data files for your reference. I am unable to plot it due to some mistake in the code.
navg = 11;
filenames = cell(navg,1);
for i = 1:navg
filenames = sprintf('queen2_test_%d.dat', i);
mydata{i}=importdata(filenames);
% writematrix(avg_mat{i}, filenames{i});
R = mydata{i}(:,1);%X
C = mydata{i}(:,2);%Y
F = mydata{i}(:,7);%F(X,Y)
figure
contour(R,C,repmat(F,1,numel(C))');
grid on;
end
saveas(gcf,figure,'.png']);

채택된 답변
Ameer Hamza
2020년 5월 5일
편집: Ameer Hamza
2020년 5월 5일
0 개 추천
Run the attached code with the files you provided
navg = 11;
filenames = cell(navg,1);
for i = 1:navg
filenames = sprintf('queen2_test_%d.dat', i);
mydata{i}=importdata(filenames);
% writematrix(avg_mat{i}, filenames{i});
R = mydata{i}(:,1);%X
C = mydata{i}(:,2);%Y
F = mydata{i}(:,7);%F(X,Y)
rg = linspace(min(R), max(R), 100);
cg = linspace(min(C), max(C), 100);
[Rg, Cg] = meshgrid(rg, cg);
Fg = griddata(R, C, F, Rg, Cg);
figure
ax = axes();
ax.YDir = 'reverse';
hold on;
contourf(Rg,Cg,Fg);
ax.XAxisLocation = 'top';
cb = colorbar('Location', 'south');
cb.Position(2) = cb.Position(2)-0.11;
grid on;
saveas(gcf,filenames(1:end-4),'png');
delete(gcf);
end
댓글 수: 19
Ameer Hamza
2020년 5월 5일
편집: Ameer Hamza
2020년 5월 5일
Note if you are using R2020a, then you can replace the saveas() line to the following line to get a better quality output
exportgraphics(gcf,[filenames(1:end-4),'.png'], 'Resolution', 300);
If you don't have R2020a, then download this package from FEX: https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig and use the following line to save high-resolution output
export_fig(gcf,[filenames(1:end-4),'.png'], '-r300');
Thanks for helping me out. I need a request.
1, I request to flip the x axis an y axis as shown in the figure.

2, contour values as shown in the below figure

Ameer Hamza
2020년 5월 5일
Run the updated code.
MS
2020년 5월 5일
Thanks, I want contour also fliped as shwon in the figure. in the updated code, the contour is not flipped.

Ameer Hamza
2020년 5월 5일
check the updated code.
MS
2020년 5월 5일
Awesome. I am really grateful to you. The axes is interferrring with the contour as shown in the figure(going inside the contour plot). is it a a bug?

Ameer Hamza
2020년 5월 5일
This problem is not happening in R2020a. As a quick-fix, you can move the axes a bit up
ax = axes();
ax.YDir = 'reverse';
ax.Position(2) = ax.Position(2)+0.02; % <=== add this line. Tune value of 0.02 until there is no overlap
MS
2020년 5월 5일
Thank you very much.
How to set same maximum and minimum axis for the plot. Please add your inputs.
caxislimit = 150;
caxis(obj.hAxes,[-caxislimit caxislimit]);
Ameer Hamza
2020년 5월 7일
What does that represent? I am not sure why that could be useful. Also, It is impossible in MATLAB. The second limit should be greater than first.
Thanks, i want the axis limt eg.,[-100 to 100]. to be same for all the figures to be saved. It will be helpful to compare the intensity between the images. Kindly let me know if you need any calrifications.

Ameer Hamza
2020년 5월 7일
Oh! I misread it to be caxis(obj.hAxes, [150 150]). Your syntax seems correct. It should show colorbar between -150 to 150.
MS
2020년 5월 7일
Thanks, i am getting error when i insert the same line in the updated code.
error:
Unable to resolve the name obj.hAxes
Ameer Hamza
2020년 5월 7일
Are you making a GUI using GUIDE? Where did you get the statement 'obj.hAxes'
MS
2020년 5월 7일
no, i got it from some gui code. I got the line correct now. Thanks for the help
caxis([-150 150])
colorbar
Ameer Hamza
2020년 5월 7일
Yes, if you have single axes then you don't need to specify an axes handle.
MS
2020년 5월 7일
okay. thank you for correcting the mistake.
hi ameer,
I want to label the colur bar as shown in the figure1.

my current code is labelling beside as shown in the figure below instead of labelling on the top as shown in the above figure1 .
h = colorbar;
xlabel(h, 'ω')
Kindly suggest a code.

MS
2020년 5월 8일
I made the code to change the postion. Thanks.
pos = get(h,'Position');
h.Label.Position = [2 30]; % to change its position
h.Label.Rotation = 0; % to rotate the text
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
참고 항목
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)
