如何在matlab中显示两条重叠线
我必须画出5条在某些区域重叠的线,我需要能够看到所有的线 我可以考虑将行移动一点,以便显示它们,但这似乎不是一个非常优雅的解决方案。即便如此,我怎么能编写这样的代码呢 是否有其他方法可以绘制多条重叠线,同时能够在每个点区分它们 例如,下面是一个有3条重叠线的示例:如何在matlab中显示两条重叠线,matlab,plot,matlab-figure,Matlab,Plot,Matlab Figure,我必须画出5条在某些区域重叠的线,我需要能够看到所有的线 我可以考虑将行移动一点,以便显示它们,但这似乎不是一个非常优雅的解决方案。即便如此,我怎么能编写这样的代码呢 是否有其他方法可以绘制多条重叠线,同时能够在每个点区分它们 例如,下面是一个有3条重叠线的示例: 提前谢谢你 可以使用plot3并为不同的重叠线指定不同的Z值。但是,如果交换Y轴和Z轴,它看起来更像您期望的(Z是“向上”方向): 例如: Y1 = randn(1,100); Y2 = randn(1,100); X = 1:10
提前谢谢你 可以使用plot3并为不同的重叠线指定不同的Z值。但是,如果交换Y轴和Z轴,它看起来更像您期望的(Z是“向上”方向): 例如:
Y1 = randn(1,100);
Y2 = randn(1,100);
X = 1:100;
Z1 = 1*ones(size(X));
Z2 = 2*ones(size(X));
plot3(X,Z1,Y1);
hold on;
plot3(X,Z2,Y2);
您可以使用打印线的
EraseMode
属性进行播放。下面的代码示例显示如何移动行和EraseMode
效果:
% First we generate some data
NLines = 2;
NPoints = 50;
LineWidth = 3;
ShiftStep = 1.1;
XData = linspace(0,1,NPoints);
YData = rand(NPoints,NLines);
for k=1:NLines
YData(:,k) = YData(:,k) > (k/(NLines+1));
end
% Then we create plot
figure('color','w');
subplot(3,1,1); plot(XData,YData, 'LineWidth',LineWidth);
ylim([-0.1 1.1]);
title('simple')
subplot(3,1,2); plot(XData,YData+repmat((0:NLines-1)*ShiftStep,NPoints,1), 'LineWidth',LineWidth, 'EraseMode','xor');
ylim([-0.1 1.1+ShiftStep*(NLines-1)]);
title('Shifted vertically')
subplot(3,1,3); plot(XData,YData, 'LineWidth',LineWidth, 'EraseMode','xor');
ylim([-0.1 1.1]);
title('EraseMode = xor')
在我看来,如果你有三条以上的线与你的情节相似,那么移动在视觉上更具吸引力。您也可以创建多个轴(就像我做的那样)并在其各自的轴上绘制每条线,这样它们将相应地设置y标签,但它们的X标签基本相同。另一种方法是使用透明度。
不幸的是,线条对象不服从
透明度命令:( 解决方法是:
1.下载(更多上下文和示例图片会有所帮助。也许线条不是可视化的正确方式?您可以在线条上使用不同形状或颜色的标记来可视化数据折叠…这些只是开/关图吗?您是否考虑过光栅图(例如)与通常用于神经数据的方法一样,
R2016a
不再支持橡皮擦模式属性,并且在将来的版本中将出错。
% create some lines:
l1 = [1, 1, 1, 0, 0, 0.25, 1, 1, 0, 0, 0, 0, 1 1];
l2 = [0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1];
l3 = [1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0];
% plot with patchline (notice the use of 'EdgeAlpha'):
figure;
patchline(1:length(l1), l1, [], 'EdgeColor', [0.8, 0.2, 0.35],...
'LineWidth', 5, 'EdgeAlpha', 0.5 );
hold on;
patchline(1:length(l1), l2, 'EdgeColor', [0.2, 0.7, 0.55],...
'LineWidth', 5, 'EdgeAlpha', 0.5 );
patchline(1:length(l1), l3, 'EdgeColor', [0.1, 0.2, 0.95],...
'LineWidth', 5, 'EdgeAlpha', 0.5);
% change y limits to see line overlap clearly
set(gca, 'YLim', [-0.5, 1.5]);