【问题标题】:How can I make a contour plot doesn't overlap on the line plot in one axes?如何使等高线图在一个轴的线图上不重叠?
【发布时间】:2014-08-09 12:13:26
【问题描述】:

我使用 matlab 指南中的按钮在一个轴上制作了 2 个图,第一个图是线图

这是剧情

http://i1275.photobucket.com/albums/y443/Kaito_Aokage/Capture2_zpsbc76be37.png?t=1403148417

线图代码

% X
for i = 1.5:7;
    cur_x = i * 3.8;
    line([cur_x, cur_x], [0 5], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% Y
for i = 2:7;
    cur_y = i * 4;
    line([0 4],[cur_y, cur_y], 'color', 'r', 'LineWidth', 1.5);
    drawnow;  
end;

% X2
for i = 1.5:7;
    cur_x2 = i * 3.8;
    line([cur_x2, cur_x2], [25 31], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% Y2
for i = 1:8;
    cur_y2 = i * 3.5;
    line([26 31],[cur_y2, cur_y2], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% X
line( [5.7 cur_x], [5 5], 'color', 'r', 'LineWidth', 1.5);

% Y
line( [4 4], [8 cur_y], 'color', 'r', 'LineWidth', 1.5);

% X2
line( [5.6 cur_x2], [25 25], 'color', 'r', 'LineWidth', 1.5);

% Y2
line( [26 26], [3.5 cur_y2], 'color', 'r', 'LineWidth', 1.5);

handles.axes2;
grid on;
hold on;
axis([0 30 0 30]);

第二个图是等高线图

http://i1275.photobucket.com/albums/y443/Kaito_Aokage/Capture3_zpsfd46dedf.png?t=1403148576

等高线图代码

xMove = 3;
yMove = 10;
r = 30;  
rx = -r:0.1:r;
ry = r:-0.1:-r;
[x_coor, y_coor] = meshgrid(rx, ry);
radius = sqrt(x_coor.^2+y_coor.^2);
contourf(x_coor + xMove, y_coor + yMove, radius,'edgecolor','none');
xlabel('Widht');
ylabel('Long');
axis([0 30 0 30]);
colorbar;
caxis([0 10]);
grid on;
handles.axes2;
set(gca,'layer','top');
hold on;

Pushbutton Floor 是线图,Pushbutton AP1 是等高线图。当我尝试在线条图按钮之后按下绘图轮廓按钮时,线条图与轮廓图重叠。我希望线图不与等高线图重叠,因此在我按下等高线图按钮后可以看到线图。我已经尝试holdset(gca,'layer','top)但它不起作用。我该怎么办?

【问题讨论】:

  • 考虑在此处插入您的数字,而不是链接它们

标签: matlab plot matlab-guide axes


【解决方案1】:

您按什么顺序执行上述代码?我首先执行了第二个代码,然后执行了第一个代码,这是我的输出

这是我执行的全部代码,我不得不删除行 handle.axis2; 因为它抛出了一个错误。(我使用的是 matlab 2011)

close all
xMove = 3;
yMove = 10;
r = 30;  
rx = -r:0.1:r;
ry = r:-0.1:-r;
[x_coor, y_coor] = meshgrid(rx, ry);
radius = sqrt(x_coor.^2+y_coor.^2);
contourf(x_coor + xMove, y_coor + yMove, radius,'edgecolor','none');
xlabel('Widht');
ylabel('Long');
axis([0 30 0 30]);
colorbar;
caxis([0 10]);
grid on;
set(gca,'layer','top');
hold on;
% X
for i = 1.5:7;
    cur_x = i * 3.8;
    line([cur_x, cur_x], [0 5], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% Y
for i = 2:7;
    cur_y = i * 4;
    line([0 4],[cur_y, cur_y], 'color', 'r', 'LineWidth', 1.5);
    drawnow;  
end;

% X2
for i = 1.5:7;
    cur_x2 = i * 3.8;
    line([cur_x2, cur_x2], [25 31], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% Y2
for i = 1:8;
    cur_y2 = i * 3.5;
    line([26 31],[cur_y2, cur_y2], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% X
line( [5.7 cur_x], [5 5], 'color', 'r', 'LineWidth', 1.5);

% Y
line( [4 4], [8 cur_y], 'color', 'r', 'LineWidth', 1.5);

% X2
line( [5.6 cur_x2], [25 25], 'color', 'r', 'LineWidth', 1.5);

% Y2
line( [26 26], [3.5 cur_y2], 'color', 'r', 'LineWidth', 1.5);


grid on;

axis([0 30 0 30]);
hold off;

【讨论】:

  • 感谢您的帮助,先生,我已经尝试过,但是我想执行第一个代码然后执行第二个代码,可以吗?
猜你喜欢
  • 1970-01-01
  • 2018-11-19
  • 1970-01-01
  • 1970-01-01
  • 2023-02-04
  • 2015-01-08
  • 2021-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多