0
막대 그래프를 사용하여 y 축에 날짜 시간과 x 축에 시간을 표시하려고합니다. 나는 y 축의 datetime의 관점에서 높이를 명시 할 필요가있다.이 matplotlib 코드의 문제점은 무엇입니까?
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import datetime as dt
# Make a series of events 1 day apart
y = mpl.dates.drange(dt.datetime(2009,10,1),
dt.datetime(2010,1,15),
dt.timedelta(days=1))
# Vary the datetimes so that they occur at random times
# Remember, 1.0 is equivalent to 1 day in this case...
y += np.random.random(x.size)
# We can extract the time by using a modulo 1, and adding an arbitrary base date
times = y % 1 + int(y[0]) # (The int is so the y-axis starts at midnight...)
# I'm just plotting points here, but you could just as easily use a bar.
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(times, y, width = 10)
ax.yaxis_date()
fig.autofmt_ydate()
plt.show()
mod 날짜가 1 일 경우 개별 시간을 알려줍니다 –
문제는 bar의 높이 매개 변수 인 것 같습니다. 나는 당신이 높이에 대한 datetime을 어떻게 먹이는지 확실하지 않다. –
아, 그렇다. 내 첫 번째 답변에 대해 미안 :'x = 크기 '대신'+ = np.random.random (y.size)'가 있어야합니다. 처음에는 오류가 발생했음을 알지 못했고, 그래서'y'가 정수로 끝나게되었습니다. 여러분이'% 1'을 할 때 '0'을주는 것은 물론입니다. 나는 그 문제가 무엇인지에 대한 나의 대답을 업데이트했다. –