MATLAB:具有多个数据集的plotyy 图例

发布于 2025-01-06 04:47:46 字数 875 浏览 2 评论 0原文

我想自动创建样品硬度 H 和杨氏模量 E 与压头负载 L 的函数关系图。

我的目标是创建包含标记为示例一的黑色圆圈标记、标记为示例二的黑色正方形的图例。现在我得到默认(蓝色)颜色的图例。

那里讨论了前面的行规范。

这是我实际的 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

感谢您的任何方法和/或更正。

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.

Preceeding line specifications are discussed there.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁许谁一生繁华 2025-01-13 04:47:46

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

例子:

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

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

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.

Example:

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

legend([h([1 3])], {'aa', 'cc'})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文