Matlab:更改线路规格 [英] Matlab: Changing line specifications

查看:69
本文介绍了Matlab:更改线路规格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的目标是使不透明标记与虚线连接.当使用set(handle,'linestyle',spec)line(...,'linestyle',spec)命令时,我得到了标记或线条,但从未同时出现-MATLAB会引发错误.
有没有办法获得线和标记而无需绘制两条具有相同数据和不同规格的线?我想像其他问题中所述继续使用图例(

My goal is to get opaque markers connected with dashed lines. When using set(handle,'linestyle',spec) or line(...,'linestyle',spec) command I got markers or lines, never both of them - MATLAB throws error.
Is there way to get lines and markers without plotting two lines with same data and different specs? I'd like to continue with this to work with legend as described in another question (MATLAB: legend for plotyy with multiple data sets).

这是我实际的MWE代码:

Here is my actual MWE code:

%data1 - m x 3 matrix with data for first sample:
[m,n]=size(data1);

%plots 1st sample data:
[ax,h1,h2]=plotyy([data1(1:m,1)],[data1(1:m,2)],[data1(1:m,1)],[data1(1:m,3)]);

set(h1,'linestyle','o')
set(h2,'linestyle','o')

%store colors:
c1=get(h1,'color');c2=get(h2,'color');

%plots 2nd sample hardness:
line('parent',ax(1),'xdata',[data2(1:m,1)],'ydata',[data2(1:m,2)],...
     'color',c1,'linestyle','s');

%plots 2nd sample young's modulus
line('parent',ax(2),'xdata',[data2(1:m,1)],'ydata',[data2(1:m,3)],...
     'color',c2,'linestyle','s');

推荐答案

我认为您可能过于复杂了?

I think you may be overcomplicating it?

尝试这样的事情:

% MarkerSize determines the size of the markers
% MarkerEdgeColor determines the color of the markers themselves
% Color determines the line color connecting them
data = rand(1,5);
plot(data, '.--', 'MarkerSize', 50, 'MarkerEdgeColor', [0.1 0.8 0.2], 'Color', [0.9 0.2 .4]);

它产生以下虚线连接的不透明标记图像:

It produces the following image of opaque markers connected with dashed lines:

要支持plotyy,该过程基本相同,除了必须在父轴和子轴上都设置一些属性.这是一些示例代码:

To support plotyy, the process is basically the same, except you have to set some properties on both the parent and child axes. Here's some example code:

% Generate some data
datax1 = rand(1,5);
datay1 = rand(1,5);
datax2 = rand(1,5);
datay2 = rand(1,5);

% Plot the data    
[ax, h1, h2] = plotyy(datax1, datay1, datax2, datay2);

% Different line styles for each child plot
set(h1, 'LineStyle', '--');
set(h2, 'LineStyle', '-.');

% Different markers for each child plot
set(h1, 'Marker', '.');
set(h2, 'Marker', '+');

% Different marker sizes for each child plot
set(h1, 'MarkerSize', 50);
set(h2, 'MarkerSize', 5);

% Generate two colors. We keep a copy so we can set the axes to match.
color1 = rand(1,3);
color2 = rand(1,3);

% The face colors are darker versions of the colors.
set(h1, 'MarkerEdgeColor', color1 * 0.5);
set(h2, 'MarkerEdgeColor', color2 * 0.5);

% This is the plot line color.
set(h1, 'Color', color1);
set(h2, 'Color', color2);

% Set the axis colors to match the plot colors.
set(ax(1), 'YColor', color1);
set(ax(2), 'YColor', color2);

产生以下图像:

这篇关于Matlab:更改线路规格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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