The below code works to create one chart from "stock1" taken from Yfinance. I am now trying to plot multiple charts using "myTickers" to collect a set of tickers from YFinance. I can get the data, but I can't get it to plot that data to multiple charts.
I want them to share the x-axis and be aligned vertically (the window can scroll if they do not fit on screen). So far any attempts have resulted in empty charts or dataframe errors that I can't solve.
I tried to adapt it to the suggestion from Daniel Goldfarb in this link Plot multiple mplfinance plots sharing x axis but so far failed to have any success. The github info for matplotlib has also not given me enough info to get past the dataframe errors.
import pandas as pd
import numpy as np
import yfinance as yf
import datetime as dt
import mplfinance as mpf
import matplotlib.pyplot as plt
from pandas_datareader import data as pdr
yf.pdr_override() # Activate Yahoo Finance Workaround
stock1 = 'M6A=F' # Gets individual ticker
# collect many tickers instead of one
myTickers = ['M6A=F','M6B=F','M6C=F','M6E=F','MBT=F','MGC=F','SIL=F','MCL=F','MES=F','MNQ=F','MYM=F','M2K=F']
startDay = 1 # Day to start gathering data
startMonth = 1 # Month to start gathering data
startYear = 2022 # Year to start gathering data
startDate = dt.datetime(startYear, startMonth, startDay) # Date to start gathering data
endDate = dt.datetime.now() # Today's date
df = pdr.get_data_yahoo(stock1, startDate, endDate) # Get data for selected stock1, from start date until today
print(df.tail())
# get data for all myTickers
#myData = pdr.get_data_yahoo(myTickers, startDate, endDate)
#print(myData.tail())
# Create custom chart style, based on Yahoo style, with black outline
chartColors = mpf.make_marketcolors(base_mpf_style="yahoo", edge="#505050", wick="#505050")
chartStyle = mpf.make_mpf_style(base_mpf_style="yahoo", marketcolors=chartColors)
# Plot custom candlestick chart for chosen stock
mpf.plot(df, type="candle", volume=True, show_nontrading=True, style=chartStyle, title="{} Daily Chart".format(stock1)) # original single chart code method
#