最近、私は時系列グラフの作成に焦点を当てています。私は時間がインデックスになるパンダを使って、すべてのCSVデータをPythonに読み込んでいます。matplotlibスクロールバーに左ボタンを追加する
プレゼンテーションの補助としてスクロールバーが追加されました。 matplotlib.widgetsからSliderをインポートして生成します。そして、すべてがうまく見えます。
しかし、私はそれを改善したいと思います。今作成したグラフは悪くないです。データポイントに移動したい場合は、スライダバーをクリックするだけです。
ただし、スライダーバーを制御するボタンを追加することは可能ですか? 私は、右のボタンを追加できますか?この右ボタンをクリックすると、グラフ全体が5データポイント右に移動します(または時系列モデルであるので5分) 「左」ボタンも作成できますか? したがって、私が速く行くなら、私はスライダーバーをクリックすることができます。次に、私がそれをゆっくりと提示したいのであれば、ボタンをクリックするだけです。
実際、「ボタンライブラリ」に関するいくつかの情報を読みました。しかし、私はそれを使ってSliderを更新する方法を知らない。
は、ここであなたが簡単にあなたがmatplotlib.widgets.Slider
追加したのと同じ方法で、プロットにmatplotlib.widgets.Button
を追加することができます私のコード
df_BA = cs_66667_BS[['BidPrice','AskPrice']]
title_name = 'cs_66667_BS'
ax = df_BA.plot(title= title_name, fontsize= 10, figsize=(20, 10))
ax.set_xlabel('Date', fontsize= 15)
ax.set_ylabel('Price', fontsize= 15)
plt.subplots_adjust(left= 0.04, bottom= 0.25, right= 0.99, top= 0.95, wspace= 0, hspace= 0.1)
x= df_BA.index.to_pydatetime()
x_min_index = 0
x_max_index = 1
x_min = x[0]
x_max = x[-1] - datetime.timedelta(minutes=4)
y_min = df_BA.BidPrice.min()
y_max = df_BA.AskPrice.max()
# timedelta
x_dt = datetime.timedelta(minutes=5)
axcolor = 'lightgoldenrodyellow'
axpos = plt.axes([0.05, 0.1, 0.9, 0.05], axisbg=axcolor)
slider_max = len(x) - x_max_index - 1
# Slider(axes, name, min, max)
spos = Slider(axpos, 'Pos', matplotlib.dates.date2num(x_min), matplotlib.dates.date2num(x_max))
# pretty date names
plt.gcf().autofmt_xdate()
def update(val):
pos = spos.val
xmin_time = matplotlib.dates.num2date(pos)
xmax_time = matplotlib.dates.num2date(pos) + x_dt
xmin_time = pos
ax.axis([xmin_time, xmax_time, y_min, y_max])
########################################################
fig.canvas.draw_idle()
spos.on_changed(update)
plt.show()
です**、ない下**ボタンです。 – ImportanceOfBeingErnest
ああ、ありがとうございました –
[この質問](http://stackoverflow.com/questions/38150315/discrete-sliders-for-multiple-sliders-python)も参照してください。 – ImportanceOfBeingErnest