我想自动创建样品的硬度H和杨氏模量E的图表,作为压头负荷L的函数。
我的目标是创建包含黑色圆圈标记的图例,标记为样本一,黑色正方形标记为样本二等。现在我得到默认(蓝色)颜色的图例。
讨论了前面的线规范there。
这是我的实际MWE代码:
[m,n]=size(data1); %data1 - m x 3 matrix with data for first sample.
[ax,h1,h2]=plotyy([data1(1:m,1)],[data1(1:m,2)],[data1(1:m,1)],[data1(1:m,3)]);
%plots 1st sample data
set(h1,'linestyle','o')
set(h2,'linestyle','o')
c1=get(h1,'color);c2=get(h2,'color'); %store colors
line('parent',ax(1),'xdata','[data2(1:m,1)],'ydata',[data2(1:m,2)],...
'color',c1,'linestyle','s') %plots 2nd sample hardness
line('parent',ax(2),'xdata','[data2(1:m,1)],'ydata',[data2(1:m,3)],...
'color',c2,'linestyle','s') %plots 2nd sample young's modulus
感谢任何方法和/或纠正。
答案 0 :(得分:1)
如果您拥有每个不同元素之一的句柄,则可以将legend
与句柄向量和图例字符串单元格一起使用。
示例:
figure
hold all
for i=1:3
h(i) = plot([i i])
end
ylim([0 4])
legend([h([1 3])], {'aa', 'cc'})