MATLAB:具有多个数据集的plottyy的图例 [英] MATLAB: legend for plotyy with multiple data sets

查看:210
本文介绍了MATLAB:具有多个数据集的plottyy的图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据压头的负载L自动创建样品的硬度H和杨氏模量E的图形.

I'd like to automatically create graphs of Hardness H and Young's modulus E of samples as function of load L of indenter.

我的目标是创建图例,其中包含标记为样本一的黑色圆圈标记,标记为样本二的黑色正方形等.

My goal is to create legend containing black circle marker labeled Sample one, black square labeled Sample two etc. Right now I get legend of default(blue) colour.

.

这是我实际的MWE代码:

Here's my actual MWE code:

[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

感谢任何方法和/或纠正.

Thanks for any approach and/or correction.

推荐答案

如果您拥有每个不同元素之一的句柄,则可以将legend与句柄向量和图例字符串单元格配合使用.

If you have the handle for one of each different elements, you can use legend with a vector of handle and a cell of legend strings.

示例:

figure
hold all
for i=1:3
    h(i) = plot([i i])
end
ylim([0 4])

legend([h([1 3])], {'aa', 'cc'})

这篇关于MATLAB:具有多个数据集的plottyy的图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆