tikzplotlib
tikzplotlib copied to clipboard
Add test case for issue #453
I've starting debugging #453 and found the place where the bug happens, but I don't know how to fix it.
https://github.com/nschloe/tikzplotlib/blob/dc919b3c538544ecf4b3d86deaf2cb9b80f0af80/tikzplotlib/_util.py#L9
def get_legend_text(obj):
"""Check if line is in legend."""
leg = obj.axes.get_legend()
if leg is None:
return None
# leg.legendHandles = [<matplotlib.collections.LineCollection object at 0x7fc13a90d278>, <matplotlib.collections.LineCollection object at 0x7fc13a90d780>]
keys = [h.get_label() for h in leg.legendHandles if h is not None] # = ['_nolegend_', '_nolegend_']
values = [t.get_text() for t in leg.texts] # = ['y1', 'y2']
# obj = <matplotlib.lines.Line2D object at 0x7fc13c957dd8>
label = obj.get_label() # = '_nolegend_'
d = dict(zip(keys, values)) # = {'_nolegend_': 'y2'}
if label in d:
return d[label] # Both return the same label
return None
Could you give guidance hints on how to proceed? I think I need to either get from the Line2D object to the LineCollection or vice versa to check if the Line2D is included in the one of the LineCollections.