2

私はstackoverflowが初めてです!Python を使用し、CSV ファイルから読み込んで、1 時間ごとの OHLC ローソク足チャートをプロットしようとしています。私の CSV ファイルには 10000 行のデータが含まれており、特定の日付範囲内のデータのみが必要ですが、日付の量は 1 つのグラフに収まりません。Sliderしたがって、関数 fromを利用してチャートをスクロール可能にしようとしていますmatplotlib.widgets。これは、私の CSV ファイルのデータの一部です。

 TimeStamp          Open    High    Low     Close
 11/7/2017 3:00     1.1395  1.1396  1.1394  1.1395
 11/7/2017 2:00     1.1394  1.1397  1.1394  1.1395
 11/7/2017 1:00     1.1396  1.1399  1.1393  1.1394
 11/7/2017 0:00     1.1398  1.1398  1.1396  1.1397
 10/7/2017 23:00    1.1398  1.1399  1.1397  1.1397
 10/7/2017 22:00    1.1399  1.1400  1.1395  1.1397
 10/7/2017 21:00    1.1401  1.1401  1.1397  1.1399
 10/7/2017 20:00    1.1401  1.1402  1.1399  1.1401
 10/7/2017 19:00    1.1404  1.1404  1.1399  1.1400
 10/7/2017 18:00    1.1407  1.1409  1.1404  1.1405
 10/7/2017 17:00    1.1397  1.1408  1.1397  1.1408
 10/7/2017 16:00    1.1397  1.1401  1.1396  1.1397
 10/7/2017 15:00    1.1389  1.1396  1.1386  1.1396
 10/7/2017 14:00    1.1393  1.1396  1.1389  1.139
 10/7/2017 13:00    1.1393  1.1394  1.1387  1.1391
 10/7/2017 12:00    1.139   1.1395  1.1386  1.1392
 10/7/2017 11:00    1.1392  1.1393  1.1384  1.139
 10/7/2017 10:00    1.1387  1.1395  1.1385  1.1395

以下は私のコードです、

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime as dt
from matplotlib.finance import candlestick_ohlc
from matplotlib.widgets import Slider

eurusd = pd.read_csv('testing.csv')
eurusd = eurusd[(eurusd['TimeStamp'] >= '10/7/2017 11:00') & 
(eurusd['TimeStamp'] <= '11/7/2017 2:00')]

eurusd['TimeStamp'] = eurusd['TimeStamp'].map(lambda d: 
mdates.date2num(dt.datetime.strptime(d, '%d/%m/%Y %H:%M')))

fig, ax = plt.subplots()
ax.xaxis_date()
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y %H:%M'))
plt.xticks(rotation = 45)
plt.xlabel("Date")
plt.ylabel("Price")
plt.title("EUR/USD")

candlestick_ohlc(ax, 
eurusd[['TimeStamp','Open','High','Low','Close']].values, width = 0.01, 
colorup = 'g')

axcolor = 'lightgoldenrodyellow'
axpos = plt.axes([0.2, 0.05, 0.65, 0.03], facecolor = axcolor)

spos = Slider(axpos, 'Position', *eurusd.head(n = 1), *eurusd.tail(n = 1))

def update(val):
    pos = spos.val
    ax.axis([pos, pos + 10, 18.5, 22.5])
    fig.canvas.draw_idle()

spos.on_changed(update)

plt.show()

コードを実行しようとしましたが、エラーが発生します - TypeError: __init__() takes from 5 to 12 positional arguments but 13 were given。誰かが私のコードを実行するのを手伝ってくれれば、本当に感謝しています。

4

0 に答える 0