Skip to content
Advertisement

pyplot combine multiple line labels in legend

I have data that results in multiple lines being plotted, I want to give these lines a single label in my legend. I think this can be better demonstrated using the example below,

JavaScript

As you can see at Out[23] the plot resulted in 5 distinct lines. The resulting plot looks like this legend of multiple line plot

Is there any way that I can tell the plot method to avoid multiple labels? I don’t want to use custom legend (where you specify the label and the line shape all at once) as much as I can.

Advertisement

Answer

I’d make a small helper function personally, if i planned on doing it often;

JavaScript

An easier (and IMO clearer) way to remove duplicates (than what you have) from the handles and labels of the legend is this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement