如果我有两个 y 向量和一个 x 向量:
y1 = [0.1,0.2,0.5,0.6];
y2 = [0.3,0.4,0.7,0.8];
x = 1:length(y1);
如何使用不同的标记和不同的颜色在同一个图上绘制所有信息。我尝试了以下方法:
cols = {'k','r','b',[0,0.5,0]};
markers = {'s','o','d','v'};
for i = 1:4;
plot(x(i),y1(i),markers{i},'color',cols{i},'MarkerEdgeColor',...
cols{i},'MarkerFaceColor','w');
hold on
end
ax1 = gca;
ax2 = axes('Position',get(ax1,'Position'),...
'YAxisLocation','right','XColor','k','YColor','k');
linkaxes([ax1,ax2],'x');
for i = 1:4;
plot(x(i),y2(i),markers{i},'color',cols{i},'MarkerEdgeColor',...
cols{i},'MarkerFaceColor',cols{i},'Parent',ax2);
hold on;
end
但这似乎覆盖了第一个情节。我的目标是用定义的标记和颜色绘制前四个点(y1),但制造商的脸是白色的。然后我希望在同一个图中包含第二个 y 轴(在右侧),其中的值来自 y2,但这次标记面根据“cols”着色。我怎样才能做到这一点?
添加:
当我使用 plotyy
for i = 1:4;
[ax,h1,h2] = plotyy(x(i),y1(i),x(i),y2(i));
hold on
set(h1,'linestyle','none','marker',markers{i},'MarkerEdgeColor',...
cols{i},'MarkerFaceColor',cols{i});
set(h2,'linestyle','none','marker',markers{i},'MarkerEdgeColor',...
cols{i},'MarkerFaceColor','w');
set(ax,{'ycolor'},{'k';'k'},{'xcolor'},{'k';'k'});
end
xaxis 值未正确显示,尽管它们相同,但它们并未在图上对齐。