Matplotlib line time series with scatter

Viewed 383

I'm struggling to make a quality chart using python, pandas and matplotlib. The goal is to have a nice line chart based on time, then based on a boolean value, have some sort of indicator (maybe a scatter on top) showing if TRUE.

Right now, it's happening, but it's very hard to see it as the circles overwrite the line. The timeframe could also be changed to 1 year or 5 years, so the dots would have to adjust. Also, the legend isn't showing.

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'])

Then call the function with the following:

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

1 Answers
Related