I'd like to define line styles in Octave (like in gnuplot) for further usage:
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. 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. 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: