How to identify which lines in the plot correspond to which legend entry?
16 views (last 30 days)
Show older comments
Waseem Akhtar
on 1 Sep 2021
Commented: Waseem Akhtar
on 1 Sep 2021
Hi,
I have a figure with multiple lines and legend entries as attached figure. Since the colours of lines are repeating several times, it's difficult to identify which line of graph corresponds to which legend.
Suggest an easy solution, please.
Thanks
1 Comment
Mathieu NOE
on 1 Sep 2021
Well
do we really need to see all those horizontal lines ? does it bring any valuable info ?
I am not sure, but I guess we could plot the data differently.
as there is no y variation we could simply plot the y mean values versus the z data (that appears for the time being in the legend)
so at the end we would simply have a 2D plot of mean(y) vs z and no need for this huge legend
Accepted Answer
Walter Roberson
on 1 Sep 2021
Edited: Walter Roberson
on 1 Sep 2021
ax = gca;
set(ax.Children(1:7:end),'Marker', '.')
set(ax.Children(2:6:end),'Marker', 'v')
set(ax.Children(1:6:end),'Marker', '^')
set(ax.Children(2:6:end),'Marker', 'v')
set(ax.Children(3:6:end),'Marker', '<')
set(ax.Children(4:6:end),'Marker', '<')
set(ax.Children(5:6:end),'Marker', '*')
set(ax.Children(6:6:end),'Marker', '+')
xlim auto
ylim auto
and now you will want to zoom in to different areas (the xlim and ylim you have in effect is only the last segment of some of the lines.)
3 Comments
Walter Roberson
on 1 Sep 2021
Edited: Walter Roberson
on 1 Sep 2021
The color selection you had repeated every 7 lines -- Children(1) and Children(8) have the same color for example.
We want to distinguish between the different lines that are the same color, so we want to assign them different Marker, in combination.
There are 30 different lines. With 7 line colors, if we use 1, 2, 3 or 4 different markers, the combinations of colors and markers would repeat after 7, 14, 21, or 28 lines, all of which would be a problem with there being 30 lines. If we use 5 different markers, then the repeat would be at 35 lines, which would be okay. 5 markers, then the repeat would be at 42 lines, which would be fine. 7 markers, the repeat would be immediate. Lowest Common Multiple rules. You could use 8 different markers for a repeat of 56 and that would be fine too.
I happened to choose to use to use 6 different markers, giving a cycle of 42 before repeating.
To set 6 different markers, set line 1, 7, 13, 19 and so on to the same marker (1:6:end), set line 2, 8, 14, 20 and so on to the same marker (2:6:end) and so on.
Note: I just fixed a typing mistake constructing the 2nd marker.
More Answers (0)
See Also
Categories
Find more on Legend 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!