Plot red lines on a contourf plot

조회 수: 20 (최근 30일)
uCiucani
uCiucani 2016년 7월 31일
댓글: uCiucani 2016년 7월 31일
Hi everybody, I am trying to create rectangles to identify some areas within a contourf plot. For the moment being, I thought of creating lines between points in the space.
I am not getting the result wanted, I only get 2 lines which I assume are represented because they are just on the rims of the contourf plot. How do I get all of them to be represented in the plot?
I attach the code hereby:
x1=[0.4:2.5:97.9,99.9];
y2=[7.9:-1.5:0.4];
y1=y2';
[X1,Y1] = meshgrid (x1,y1);
%-------
HV_NDTD1=[466, 468, 440, 463, 463, 480, 444, 463, 454, 446, 468, 448, 463, 461, 457, 452, 477, 440, 448, 463, 466, 480, 477, 459, 457, 455, 444, 448, 461, 442, 452, 435, 448, 444, 470, 463, 461, 457, 463, 459, 450;
452, 487, 475, 470, 457, 487, 468, 475, 497, 461, 475, 463, 494, 435, 472, 487, 444, 468, 472, 450, 470, 450, 470, 461, 461, 448, 463, 457, 463, 480, 457, 457, 463, 468, 466, 492, 459, 472, 455, 475, 472;
418, 442, 429, 412, 404, 410, 403, 423, 427, 418, 427, 438, 461, 446, 442, 448, 435, 440, 437, 431, 448, 431, 433, 455, 431, 472, 435, 444, 470, 446, 484, 442, 448, 450, 477, 446, 468, 459, 477, 452, 470;
408, 394, 394, 399, 418, 416, 392, 403, 423, 425, 406, 414, 406, 435, 425, 435, 431, 446, 427, 454, 406, 448, 429, 438, 448, 454, 446, 444, 450, 446, 466, 440, 420, 461, 425, 448, 466, 459, 452, 468, 461;
423, 423, 442, 431, 404, 412, 418, 406, 397, 446, 454, 448, 433, 442, 466, 461, 461, 450, 440, 440, 440, 452, 457, 452, 440, 448, 468, 475, 440, 461, 448, 463, 466, 444, 455, 475, 440, 452, 442, 433, 463;
410, 403, 480, 468, 440, 442, 446, 446, 452, 410, 431, 457, 468, 454, 450, 470, 431, 423, 470, 459, 454, 435, 455, 461, 457, 459, 468, 470, 468, 466, 468, 461, 461, 468, 477, 487, 457, 468, 475, 463, 452;];
%------
xLINE1=[35.3 99.9];
yLINE1=[0.4 0.4];
xLINE2=[35.3 99.9];
yLINE2=[3.3 3.3];
xLINE3=[40.3 99.9];
yLINE3=[5 5];
xLINE4=[40.3 99.9];
yLINE4=[7.9 7.9];
xLINE5=[35.3 35.3];
yLINE5=[0.4 3.3];
xLINE6=[40.3 40.3];
yLINE6=[0.4 3.3];
%---------
figure(3);
plot(xLINE1,yLINE1,'r-','linewidth',6)
hold on;
plot(xLINE2,yLINE2,'r-','linewidth',6)
plot(xLINE3,yLINE3,'r-','linewidth',6)
plot(xLINE4,yLINE4,'r-','linewidth',6)
plot(xLINE5,yLINE5,'r-','linewidth',6)
plot(xLINE6,yLINE6,'r-','linewidth',6)
contourf(X1,Y1,HV_NDTD1)
colormap(parula(32))
colorbar
hold off;
xlabel('Distance (mm)','FontSize',16)
ylabel('Distance (mm)','FontSize',16)
title('W80 Plate ND/TD Bar Hardness Map (facing encapsulated samples)','FontSize',22,'FontWeight','bold')
set(gca,'fontsize',24,'fontweight','bold','linewidth',3);
x1 = [.8,.775];
y1 = [0.965,0.935];
a = annotation('textarrow',x1,y1,'String','Front RD/TD-surface','fontweight','bold');
a.Color = 'red';
a.FontSize = 20;
x1 = [.1,.125];
y1 = [0.85,0.775];
a = annotation('textarrow',x1,y1,'String','Crizzled side','fontweight','bold');
a.Color = 'red';
a.FontSize = 20;

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 7월 31일
uCiucani - try drawing the red lines after you have created the contour plot as
contourf(X1,Y1,HV_NDTD1)
hold on;
plot(xLINE1,yLINE1,'r-','linewidth',6)
plot(xLINE2,yLINE2,'r-','linewidth',6)
plot(xLINE3,yLINE3,'r-','linewidth',6)
plot(xLINE4,yLINE4,'r-','linewidth',6)
plot(xLINE5,yLINE5,'r-','linewidth',6)
plot(xLINE6,yLINE6,'r-','linewidth',6)
Or, better, is to use uistack to re-order the visual stacking order of the graphics objects. In this case, you would "put" the contour plot at the bottom of the stack
figure(3);
hold on;
plot(xLINE1,yLINE1,'r-','linewidth',6)
plot(xLINE2,yLINE2,'r-','linewidth',6)
plot(xLINE3,yLINE3,'r-','linewidth',6)
plot(xLINE4,yLINE4,'r-','linewidth',6)
plot(xLINE5,yLINE5,'r-','linewidth',6)
plot(xLINE6,yLINE6,'r-','linewidth',6)
[~, hCP] = contourf(X1,Y1,HV_NDTD1);
uistack(hCP,'bottom');
Try the above and see what happens!
  댓글 수: 1
uCiucani
uCiucani 2016년 7월 31일
It worked, thank you very much Geoff!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by