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

Define custom linestyles in Octave for use on multiple figures

我想在 Octave 中定义线条样式(如在 gnuplot 中)以供进一步使用:

我在想这样的事情:

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

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

等等。但是这样的事情没有奏效。有人对如何解决这个问题有什么建议吗?

提前致谢。

让我们看看,MATLAB 是干什么的,照搬思路: Comma-Separated Lists as Function Call Arguments. 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 可以正常使用。请参阅以下代码片段以获取您给出的示例的解决方案。

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

并且,这是一个示例性输出: