【发布时间】:2021-05-10 22:09:13
【问题描述】:
我有一些想要绘制的数据。我正在使用下面的代码:
import pandas_datareader as web
crypto_currency = 'BTC'
against_currency = 'USD'
start, end = dt.datetime(2012,1,1), dt.datetime.now()
df = web.DataReader(f'{crypto_currency}-{against_currency}', 'yahoo', start, end)
df.head()
数据框看起来像这样,
例如,如果我想绘制接近值,我会执行以下操作:
import seaborn as sns; sns.set(style="whitegrid")
import matplotlib.pyplot as plt
close_values = df.filter(['Close']).values
plt.figure(figsize=(20,8))
plt.plot(close_values, label=f'Close values')
plt.xlim(0, len(close_values))
plt.title(f'{crypto_currency}-{against_currency} close data')
plt.legend()
plt.show()
图表如下所示:
没关系,但我想在 X 轴上显示日期。我以为我只需要从索引中获取日期值并将它们添加为 X 轴,但这是错误的。我的编码是错误的还是在概念上是错误的?我知道这应该很容易,但我不知道该怎么做。
【问题讨论】:
标签: python pandas matplotlib