Q:

can't see Date/Time in the cursor position while plotting a graph with matplotlib. Getting error as "DateFormatter found a value of x=0"

I have a timestamp list like:
['2018-06-28 20:00:00', '2018-06-28 20:00:05', '2018-06-28 20:00:10', '2018-06-28 20:00:15', '2018-06-28 20:00:20', '2018-06-28 20:05:30']

I am plotting graph like this, where timestamp and iops is a list like:
p1, = host.plot(timestamp[0:], iops[0:], "b-", label="IOPS")

I have set x_lim as:
host.set_xlim([timestamp[0],timestamp[-1]])

This is what i have done to show timestamp on x axis:
_fmt = mdates.DateFormatter('%Y-%m-%d')
_fmt.format_data_short = lambda pos: mdates.num2date(pos).strftime("%Y-%m-%d; %H:%M:%S")
 host.xaxis.set_major_formatter(_fmt)

A:

The full error message reads

ValueError: DateFormatter found a value of x=0, which is an illegal date.  This usually occurs because you have not informed the axis that it is plotting dates, e.g., with ax.xaxis_date()

And that is true indeed, because you are plotting strings here and matplotlib cannot know that they carry a meaning as "date" for you.
The solution is to convert them to dates.
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import  datetime

timestamp= ['2018-06-28 20:00:00', '2018-06-28 20:00:05', '2018-06-28 20:00:10', 
            '2018-06-28 20:00:15', '2018-06-28 20:00:20', '2018-06-28 20:05:30']
dates = [datetime.strptime(t, "%Y-%m-%d %H:%M:%S") for t in timestamp]
y = list(range(6))

fig, ax = plt.subplots()
p1, = ax.plot(dates, y, "b-", label="IOPS")

ax.set_xlim([dates[0],dates[-1]])

_fmt = mdates.DateFormatter('%Y-%m-%d')
_fmt.format_data_short = lambda pos: mdates.num2date(pos).strftime("%Y-%m-%d; %H:%M:%S")
ax.xaxis.set_major_formatter(_fmt)

plt.show()

