How to differentiate 2 overlapping lines in matlab by
19 views (last 30 days)
Show older comments

There are 4 graphs here, each with their own color. However, the first line on the left is common between all 4 graphs. So is there a way to recolor just that portion with the mixture of all 4 chosen legend colours to show this is a common part of all 4 graphs?
What i have:
plot(x,y);
xlabel('x');
ylabel('y');
ylim([0,inf]);
title('Trajectory: X vs Y');
hold on;
legend('k=0','k=0.0005','k=0.001','k=0.0015');
0 Comments
Answers (1)
Walter Roberson
on 7 Apr 2018
There is no way to do it automatically.
You should consider experimenting with a mix of line styles and marker styles. Avoid the - line style on top, but -- and -: can leave gaps where the others can show through, and some of the marker shapes do not completely hide others of the shapes.
If you want one line with multiple colors then there are a couple of File Exchange contributions that can take care of that, one of which works using a surface() object and another uses a patch() object.
4 Comments
Walter Roberson
on 7 Apr 2018
lh = plot(x,y);
set(lh(1), 'Linestyle', '--');
set(lh(2), 'Linestyle', ':');
set(lh(3), 'Linestyle', '-.');
set(lh(4), 'Linestyle', 'none', 'Marker', 'v')
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!