import pandas as pd
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
from matplotlib.finance import candlestick_ohlc
import matplotlib.dates as mdates
import datetime as dt
import urllib
import json
from urllib.request import urlopen
import datetime as dt
import requests
dataLink ='http://api.huobi.com/staticmarket/btc_kline_015_json.js'
r = requests.get(dataLink) # r is a response object.
quotes = pd.DataFrame.from_records(r.json()) # fetches dataset
quotes[0] = pd.to_datetime(quotes[0].str[:-3], format='%Y%m%d%H%M%S')
#Naming columns
quotes.columns = ["Date","Open","High",'Low',"Close", "Vol"]
#Converting dates column to float values
quotes['Date'] = quotes['Date'].map(mdates.date2num)
#Making plot
fig = plt.figure()
fig.autofmt_xdate()
ax1 = plt.subplot2grid((6,1), (0,0), rowspan=6, colspan=1)
#Converts raw mdate numbers to dates
ax1.xaxis_date()
plt.xlabel("Date")
print(quotes)
#Making candlestick plot
candlestick_ohlc, (ax1,quotes.values,width=1,colorup='g',colordown='k',
alpha=0.75)
plt.show()
我試圖繪製由Huobi提供JSON數據陰陽燭圖,但我不能日期出來&情節看起來可怕排序。你能用相當簡單的術語來解釋一下,新手可能會明白我做錯了什麼嗎?這是我的代碼....不能從繪製JSON Huobi數據燭臺數據
THX,在advance`
Thx。我發現,如果通過將dataLink ='http://api.huobi.com/staticmarket/btc_kline_015_json.js'行更改爲dataLink ='http:// api,從15分鐘數據更改爲日期數據,燭臺顯示正確。 huobi.com/staticmarket/btc_kline_100_json.js' – user1613312
實際上,改變'http://api.huobi.com/staticmarket/btc_kline_015_json.js'以獲得不同的週期和長度參數解決了這個問題...我認爲 – user1613312