Reputation:
When I adjust line width for this type of plot it works.
plot(x1,y1, 'm','Linewidth',1)
hold on
plot(x2,y2, 'b','Linewidth',2)
hold on
plot(x3,y3, 'r','Linewidth',3)
hold on
plot(x4,y4, 'c','Linewidth',4)
hold on
plot(x5,y5, 'o','Linewidth',5)
But not when I do this.
plot(x1, y1, 'm','Linewidth',1,x2, y2, 'b','Linewidth',2,x3, y3, 'r','Linewidth',3,x4, y4, 'c','Linewidth',4,x5, y5, 'o','Linewidth',5);
I get an error.
Is it possible to adjust line width for a combined plot?
Upvotes: 0
Views: 1367
Reputation: 667
I don't like using hold since it is hard to know if it is on or off when you do the next plot. I like to use plot for the first line and line for subsequent lines like this:
plot(x1, y1, 'm', 'linewidth', 1)
line(x2, y2, 'color', 'b', 'linewidth', 2)
line(x3, y3, 'color', 'r', 'linewidth', 3)
line(x4, y4, 'color', 'c', 'linewidth', 4)
line(x5, y5, 'color', 'o', 'linewidth', 5)
Upvotes: 1
Reputation: 1808
An alternate approach that is more scalable for greater numbers of plots and/or extra properties uses arrayfun
. Basically, if you set up the data for all your plots in arrays, you can then plot all data with only one line of code
% set up the data and all plot attributes
x = {x1, x2, x3, x4, x5};
y = {y1, y2, y3, y4, y5};
styles = ['m', 'b', 'r', 'c', 'o'];
widths = [1, 2, 3, 4, 5];
% setup figure
figure
ax = axes('NextPlot','add'); % like calling hold on
% plot all elements
% equivalent to a for loop: for i = 1:length(x)
arrayfun(@(i) plot(ax, x{i}, y{i}, styles(i), 'linewidth', widths(i)), 1:length(x));
Upvotes: 2
Reputation: 35525
Is it possible to adjust line width for a combined plot?
No (well yes but not in a cleaner way).
You can adjust the parameters for all of them together if you want a single line. If you want control over the appearance of each of them, you will need to do separate plots.
You can do it accessing the properties, but I suspect that is just longer and less clear, so not sure if it is really the right solution.
h=plot(x1, y1, x2, y2, ...);
h(1).LineWidth=1;
h(2).LineWidth=2;
...
Upvotes: 3