以下是相关问题的情节。深色线条覆盖了x轴,但由于某种原因,我无法调试此问题。我正在尝试绘制来自数据框的两列,即代码中可以看到的时间对3期SMA价格的图表。
任何帮助都将不胜感激。谢谢。
这是代码的结果
import datetime
import matplotlib.pyplot as plt
import pandas as pd
from binance.client import Client
BASE = "ETH"
QUOTE = "USDT"
MARKET = BASE + QUOTE
client = Client("vitalik",
"buterin")
klines = client.get_historical_klines(MARKET, Client.KLINE_INTERVAL_15MINUTE, "31 Dec, 2017", "13 Jan, 2018")
# temporary fix
for kline in klines:
kline[0] = datetime.datetime.fromtimestamp(
int(kline[0] / 1000)
).strftime('%Y-%m-%d %H:%M:%S')
kline[6] = datetime.datetime.fromtimestamp(
int(kline[6] / 1000)
).strftime('%Y-%m-%d %H:%M:%S')
df = pd.DataFrame(klines,
columns=["open_time", "open", "high", "low", "close", "volume", "close_time", "quote_asset_volume",
"trades", "base_volume", "quote_volume", "ignore"])
df['sma_3'] = df["close"].rolling(window=3).mean()
print(df.dtypes)
fig, ax = plt.subplots(figsize=(10, 6))
ax.xaxis_date()
plt.xticks(rotation=90)
plt.xlabel("Date")
plt.ylabel("Price")
plt.title(MARKET)
plt.plot_date(x=df["close_time"], y=df["sma_3"], fmt="r-")
plt.show()
print(df.dtypes)
的结果是:
open_time object
open object
high object
low object
close object
volume object
close_time object
quote_asset_volume object
trades int64
base_volume object
quote_volume object
ignore object
sma_5 float64
sma_3 float64
dtype: object
任何帮助都将不胜感激。谢谢。
print(ax.xaxis.get_ticklabels())
返回什么? - jezrael