0
私は棒グラフを使ってy軸上のdatetimeと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()
1のmod日付はあなたに個々の時間を与えます –
問題はバーの高さパラメータであるようです。私は高さのためにdatetimeをどのように供給するのか分かりません –
ああ、私は同意します。私の最初の答えについては申し訳ありません: 'x = size 'の代わりに' + = np.random.random(y.size) 'を使うべきです。最初は私はエラーが発生したことに気付かなかったので、私の 'y'は整数の束になりました。もちろん'%1'を実行すると '0'が返されます。私は、私が問題と思われるものに私の答えを更新しました。 –