【发布时间】:2019-12-02 05:33:58
【问题描述】:
我有一个标记为 data 的数据框字典:which holds information about stocks and their pricing/volumes, etc...
我想遍历并绘制所有键和特定值。我正在升级我构建的原始程序,该程序仅适用于一种股票。我想通过给我的程序一个可以使用的股票列表来将它提升到一个新的水平,在这种情况下,股票列表称为tickers = ["LRCX", "FB", "COF"]
下面是我的原始程序如何仅绘制一只股票(又名一个数据框)。
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(14,5))
ax1.plot(dte_df["date"], dte_df["Close"])
ax1.set_xlabel("Date", fontsize=12)
ax1.set_ylabel("Stock Price")
ax1.set_title(f"{ticker} Close Price History")
# first Subplot (layer two)
ax1.plot(dte_df["date"], dte_df["High"], color="green")
ax1.set_xlabel("Date", fontsize=12)
ax1.set_ylabel("Stock Price")
ax1.set_title(f"{ticker} High Price History")
# first Subplot (layer three)
ax1.plot(dte_df["date"], dte_df["Low"], color="red")
ax1.set_xlabel("Date", fontsize=12)
ax1.set_ylabel("Stock Price")
ax1.set_title(f"{ticker} Low Price History")
# Second Subplot
ax2.plot(dte_df["date"], dte_df["Volume"], color="orange")
ax2.set_xlabel("Date", fontsize=12)
ax2.set_ylabel("Stock Price")
ax2.set_title(f"{ticker} Volume History")
plt.show()
上面的代码有两个子图。每日股价(最高价、最低价、收盘价)在一张图上,然后在另一张图上股票成交量。我正在尝试复制此代码,但要使用字典循环遍历键,而不是仅包含一只股票的数据框。我从来没有以这样的身份处理过字典,非常感谢您提前提供的任何帮助和指导,
干杯!
【问题讨论】:
标签: python dictionary matplotlib plot