0

您好,我正在尝试绘制一些加密货币的图表。我正在尝试绘制 BTC/USD 图表,但它不起作用。这是我的代码:

from urllib.request import Request, urlopen
import json
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import datetime as dt    
from mpl_finance import candlestick_ohlc
import matplotlib.dates as mdates

url = "https://api.binance.com/api/v1/klines?symbol=BTCTUSD&interval=1h"
reponse = urlopen(url)
data = json.load(reponse)
df = pd.DataFrame(data)
df.columns = ['open_time', 'o', 'h', 'l',
              'c', 'v', 'close_time',
              'qav', 'num_trades', 'taker_base_', 'taker_quote_vol',
              'ignore']
df['close_time'] = pd.to_datetime(df['close_time'], unit='ms')
df['close_time'] = df['close_time'].apply(mdates.date2num)
df['o'] = df['o'].astype('float')
df['h'] = df['h'].astype('float')
df['l'] = df['l'].astype('float')
df['c'] = df['c'].astype('float')
df['v'] = df['v'].astype('float')
ax1 = plt.subplot2grid((1,1), (0,0))
ohlc = [df['close_time'], df['o'], df['h'], df['l'], df['c'], df['v']]
candlestick_ohlc(ax1, ohlc)

但是当我尝试执行这段代码时,我得到的只是一个白屏,但没有图表,这很奇怪!

请问你能帮帮我吗 ?

非常感谢 !

4

0 回答 0