Matplotlib y-axis date

I am trying to build a series of sunset times in matplotlib, but I get the following error: "TypeError: Empty 'DataFrame': no ​​numeric data to plot

I looked through several options for conversion, for example. plt.dates.date2num, but it really does not fill my needs, because I would like to build it in a readable format, that is, time. All the examples I found have times on the x axis, but don't have them on the y axis.

Is there no way to accomplish this task? Has anyone got an idea?

I really hope for your answers. Best regards, Arne

3 Jan 2013          16:44:00
4 Jan 2013          16:45:00
5 Jan 2013          16:46:00
6 Jan 2013          16:47:00
7 Jan 2013          16:48:00
8 Jan 2013          16:49:00
9 Jan 2013          16:51:00
10 Jan 2013         16:52:00
11 Jan 2013         16:53:00
12 Jan 2013         16:55:00
13 Jan 2013         16:56:00
14 Jan 2013         16:57:00
+4
source share
1 answer

, x / y x y.

, , .

, pandas, , : ​​ .

, ax.xaxis_date() ax.yaxis_date(). . ( , .)

import matplotlib.pyplot as plt
import matplotlib.dates as mdates

date = ['3 Jan 2013', '4 Jan 2013', '5 Jan 2013', '6 Jan 2013', '7 Jan 2013',
        '8 Jan 2013', '9 Jan 2013', '10 Jan 2013', '11 Jan 2013', '12 Jan 2013',
        '13 Jan 2013', '14 Jan 2013']
time = ['16:44:00', '16:45:00', '16:46:00', '16:47:00', '16:48:00', '16:49:00',
        '16:51:00', '16:52:00', '16:53:00', '16:55:00', '16:56:00', '16:57:00']

# Convert to matplotlib internal date format.
x = mdates.datestr2num(date)
y = mdates.datestr2num(time)

fig, ax = plt.subplots()

ax.plot(x, y, 'ro-')
ax.yaxis_date()
ax.xaxis_date()

# Optional. Just rotates x-ticklabels in this case.
fig.autofmt_xdate()
plt.show()

enter image description here

+2

All Articles