Matplotlib行时间系列与散点图

问题描述:

我努力使用python,熊猫和matplotlib制作质量图表。目标是根据时间有一个很好的折线图,然后基于一个布尔值,有某种指标(可能是顶部的散点图),显示是否为TRUE。Matplotlib行时间系列与散点图

现在正在发生这种情况,但很难将其视为圆圈覆盖该行。时间也可以更改为1年或5年,所以点必须调整。另外,图例没有显示。

def plot_stock(stock_prices_bollinger, ticker): 
plt.title(ticker) 
# y label 
plt.ylabel('stock price') 
# and a legend 
plt.legend(loc='upper right') 
plt.plot(stock_prices_bollinger['Price']) 
return plt.scatter(stock_prices_bollinger.index, stock_prices_bollinger['Price'], c=stock_prices_bollinger['breakout']) 

然后调用函数有以下:

ticker = 'MMM' 
from_date = '2011-01-01' 
to_date = '2016-10-01' 

Prices = stock_info(ticker, pd.to_datetime(from_date, format='%Y-%m-%d'), 
pd.to_datetime(to_date, format='%Y-%m-%d')) 
Prices_breakout = bollinger(Prices) 
plot_stock(Prices_breakout, ticker) 

enter image description here

+0

您的plt.plot和plt.scatter中没有任何标签,因此图例不显示。 – taras

我没有具体的答案,但如果你试图绘制股票价格与熊猫和matplotlib,你可能会发现这个链接有帮助:

https://ntguardian.wordpress.com/2016/09/19/introduction-stock-market-data-python-1/

去年我尝试熟悉大熊猫时,我经历过它,我认为这是非常有益的。