cphyc / matplotlib-label-lines

Label line using matplotlib.
MIT License
301 stars 28 forks source link

Support for pandas DataFrame with DatetimeIndex #6

Closed soxofaan closed 5 years ago

soxofaan commented 6 years ago

Hi, thanks for this great matplotlib "plugin"

I couldn't get it to work yet on pandas based plots with a DatetimeIndex:

screen shot 2018-10-24 at 11 43 01

Any ideas, and is there any interest in supporting this? I already had a quick look, but couldn't find a quick fix yet as date handling is quite messy territory

cphyc commented 6 years ago

Hey, thank you very much for your feedback.

I am not using labelled lines and dates personally so it would be hard for me to figure out a workaround.

This should however be fixable by modifying the labelLine function (https://github.com/cphyc/matplotlib-label-lines/blob/81daa2d2e0af1b620bd76cb8257beb1749b34549/labellines/core.py#L37) and add support for datetimes.

This could be as simple as replacing https://github.com/cphyc/matplotlib-label-lines/blob/81daa2d2e0af1b620bd76cb8257beb1749b34549/labellines/core.py#L24 by

xdata = line.get_xdata()
if isinstance(xdata[0], datetime):
    xdate = [date2num(_) for _ in xdata]

and the same for ydata.

soxofaan commented 6 years ago

I found some time to work on this: see PR #8

cphyc commented 5 years ago

This should be fixed by #8 so I'm closing for now.