How do I create a legend that is "disconnected" from the plotted items
1 次查看(过去 30 天)
显示 更早的评论
Dear all, I have the following problem. I would like to plot various items that can take two colors, say red and blue. The color of each item depends on the sign of the numbers plotted.
In order to handle such a situation I would like to be able to create a legend with exactly two entries. The first one sets the red color to negative and the blue color to positive.
The reason I call it disconnected is because (1) there could be more than two items plotted, (2) a plot need not have items of both colors.
Ideally then I should be able to add a legend even before plotting.
Is this a problem that is solvable in matlab?
Thanks
1 个评论
Adam
2017-5-15
You can use:
hasbehavior( hLine, 'legend', false );
to ensure that a given line is not picked up by the legend automatically.
In terms of the rest though it sounds more like you just want text on the plot rather than a legend.
Theoretically you could achieve this by using the above on all your actual plots and then just plot two objects out of the axis limits, one blue, one red that would appear on the legend as blue and red. It's not a nice solution though, there may be better ones.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!