0

I load a csv in a pandas dataframe (one column is full of datime values):

def edit(filename):
    df = pd.read_csv ( filename, sep=';',decimal=',', skiprows=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], error_bad_lines=False )

    df = df[['TimeString','VarValue']]


    df['TimeString'] =  pd.to_datetime(df['TimeString'], format='%d/%m/%Y %H:%M:%S')
    df['VarValue'] = pd.to_numeric(df['VarValue'])

    return df

I draw a plot with plot_date:

def plotting(self, df):
    self.axes.grid(True)
    self.axes.plot_date(df['TimeString'], df['VarValue'],'-',label='MACD_14_21')
    self.axes.legend(loc='upper left')
    self.canvas.draw()

enter image description here

Now I would like to use the function:

def onMouseMove(self, event):
    print(event.xdata, event.ydata)

cid = self.canvas.mpl_connect('motion_notify_event', self.onMouseMove)

What I get is:

737235.953598 91.53

So The event.ydata works fine, but the event.xdata instead of give me a datetime values is giving me a unknown float64. But in the meanwhile the GUI inferface is going to get the correct X data value:

enter image description here

So, How can I get the right datetime value? Or how can I convert the float value in a datetime value?

Thank you so much for your help

Luca

PS: all the tutorials shown the possibility to use the normal plot with datetime values too but when I use it with so many data (>20k) the plotting is very slow.

  • 1
    [this](https://stackoverflow.com/a/2623191/11305111) might help. otherwise, if you could include all the code to reproduce that would be helpful. – jayveesea May 17 '20 at 11:39
  • Yeah, this was a good starting point to start to play with data: days and hours. Thanks! – Luca Dalbosco Oct 31 '20 at 17:54

0 Answers0