python - 从 csv 文件中绘制股票数据,未正确显示日期?
问题描述
希望有人能指出我正确的方向。
我是 Matplotlib 的新手。我有一个 .csv 的股票数据,看起来像这样......
...我想绘制开盘价,日期为 X 标签。这就是我现在正在使用的:
stock_prices = pd.read_csv(cache_filename)
# Plot the open prices
stock_prices['1. open'].plot()
plt.title('Daily Time Series for the stock (from saved CSV file)')
plt.xlabel('day')
plt.ylabel('price')
plt.show()
...但是 X 轴标记为 Day,但它只显示数字计数,而不是日期值:
我需要添加什么以确保 X 轴标有日期?或者指点我资源。非常感谢!
解决方案
尝试
import matplotlib.pyplot as plt
plt.plot(stock_prices['date'],stock_prices['1. open'])
plt.title('Daily Time Series for the stock (from saved CSV file)')
plt.xlabel('day')
plt.ylabel('price')
推荐阅读
- kubernetes - Minio 数据不会通过重新启动保留
- python - 为 PCA 生成加载矩阵时如何将 pandas 数据框列设置为索引
- excel - 从另一个工作簿复制/覆盖工作表
- python - 如何解决 Python 中的 KeyError?
- node.js - Req.body 适用于 POST req 但不适用于 GET req。使用正文解析器
- reactjs - 使用asp .net core web api配置react js应用程序的最佳方法是什么
- python - 从 1 通道阵列到带有 if 条件的 3 通道
- javascript - 将类添加到动态变化的元素
- python - 不同的“运行时错误:尝试使用关闭的会话。”
- redirect - 通过 commandButton 操作重定向不适用于 PF 7 中的相对路径