简体   繁体   English

在Octave中定义自定义线型以用于多个图形

[英]Define custom linestyles in Octave for use on multiple figures

I'd like to define line styles in Octave (like in gnuplot) for further usage: 我想在Octave中定义线条样式(例如gnuplot中)以供进一步使用:

I was thinking about something like that: 我在想这样的事情:

styles = {['color',[.5 .2 .8],'--', 'linewidth', 1.25], ['or', markersize, 4], 
['-sb', markersize, 2]}

plot (x,y, styles{1})
plot (x,y, styles{2})

and so on. 等等。 But such a thing didn't work. 但是这样的事情没有用。 Does someone have any suggestions how to solve this? 有人对如何解决这个问题有任何建议吗?

Thanks in advance. 提前致谢。

Let's have a look, what MATLAB does and copy the ideas: You can use Comma-Separated Lists as Function Call Arguments . 让我们看一下MATLAB的工作并复制思想:您可以将逗号分隔的列表用作函数调用参数 Actually, there's an example describing exactly, what you want to achieve. 实际上,有一个示例准确描述了您想要实现的目标。 Nevertheless, to get this working as you'd like to, you also have to "disassemble" the LineSpec properly. 但是, LineSpec此功能按您希望的那样工作,还必须正确地“分解” LineSpec Please see the following code snippet to get the solution for the examples given by you. 请参见以下代码片段,以获取您给出的示例的解决方案。

x = linspace(0, 2*pi, 50);

% styles = {['color',[.5 .2 .8],'--', 'linewidth', 1.25], ['or', markersize, 4], ['-sb', markersize, 2]}

styles = {
  {'Color', [.5 .2 .8], 'LineStyle', '--', 'LineWidth', 1.25}, ...
  {'Color', 'r', 'Marker', 'o', 'MarkerSize', 4}, ...
  {'Color', 'b', 'LineStyle', '-', 'Marker', 's', 'MarkerSize', 2} ...
};

figure(1);
hold on;

for ii = 1:numel(styles)
  plot(x, sin(x + ii * pi/4), styles{ii}{:});
end

hold off;

legend();

And, here is an exemplary output: 并且,这是示例输出:

示范输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM