matplotlib-label-lines
matplotlib-label-lines copied to clipboard
Unable to reproduce last notebook example
Problem
The last example in the example notebook is not reproducing what is shown in the repository. The labels on the dashed lines are incorrect. There is a mismatch between the lines and the label shown on the lines when specifying the lines
parameter in labelLines
.
Image produced when I run the example:
It appears this problem is a result of using the labels from the all_labels
variable from the ax.get_legend_handles_labels()
call on line 130. The for loop at line 199 in core.py
assumes that all_labels
and all_lines
have the same ordering, which may not always be true if the lines
parameter is specified.
It looks like the example notebook hasn't been updated in 3 years, so I presume some change to core.py
in the meantime has resulted in this issue.
Tentative solution
I was able to fix this by ignoring the all_labels
variable and reading the label directly from the line object when iterating through all_lines
. This can be done by changing line 200 to the following: label = line.get_label()
.
However, perhaps there is a reason this is not already the default. I did not test this with every line object in matplotlib, so there could be some objects in matplotlib that do not support the get_label
method.
Thanks
Despite this issue, this is a nice package. I appreciate the work put into it, and I plan on using it :)
Oh yep, that looks like a bug! I am quite oversubscribed but I'd be happy to review a pull request should you find time to fix this :)
So it turns out I don't have much time to track that issue down. This is a new-contributor friendly bug, so please (anyone) feel free to fix!