Matlab:改变生产线规范

标签 matlab plot line

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

我的目标是让不透明标记与虚线连接。使用 set(handle,'linestyle',spec)line(...,'linestyle',spec) 命令时,我得到了标记或线条,但两者都不是- MATLAB 抛出错误。
有没有办法获得线条和标记,而无需绘制具有相同数据和不同规范的两条线?我想继续使用另一个问题(MATLAB: legend for plotyy with multiple data sets)中描述的图例。

这是我实际的 MWE 代码:

%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');

最佳答案

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

尝试这样的事情:

% 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]);

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

Plot

为了支持 plotyy,过程基本相同,只是您必须在父轴和子轴上设置一些属性。下面是一些示例代码:

% 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);

生成以下图像:

enter image description here

关于Matlab:改变生产线规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9329087/

相关文章:

three.js - 三个JS虚线 Material 不显示

javascript - 重绘简单图形

arrays - 从 Matlab 元胞数组中获取唯一行

R:如何通过数据值对 voronoi 镶嵌进行着色?

image - 使用平均滤波器部分模糊图像

plot - 如何在 gnuplot 中为 xticlabels 提供自定义字符串参数?

python - 高效更新多个 pyplots

r - 使用箱线图添加线图

matlab - MATLAB中是否有图像处理函数来获取二值图像的骨架

java - %{ ... %} 评论的正则表达式