data_file_download.py

from datetime import datetime
import time
import pandas as pd

tickers = ['TSLA', 'AAPL', 'AMZN', 'UAL']
datasets = {}

# year to day
today_timestamp = int(datetime.now().timestamp())
for ticker in tickers:
    url = f'https://query1.finance.yahoo.com/v7/finance/download/{ticker}?period1=1640995200&period2={today_timestamp}&interval=1d&events=history&includeAdjustedClose=true'
    df = pd.read_csv(url, parse_dates=['Date'])
    datasets[ticker] = df
    df['Ticker'] = ticker
    time.sleep(1)

df_master = pd.concat(datasets)
df_master.reset_index(drop=True).to_csv('dataset.csv', index=0)



demo.py

import random
import pandas as pd
import matplotlib.pyplot as plt

# Read data into a pandas dataframe
data = pd.read_csv("dataset.csv")
tickers = data['Ticker'].unique()[:4]
# generate 20 random hex colors
colors = ["#{:06x}".format(random.randint(0, 0xFFFFFF)) for i in range(20)]

n_row = 2
n_col = round((len(tickers) / n_row) + 0.5)

# Create a new figure with specified number of rows and columns
fig, axes = plt.subplots(nrows=n_row, ncols=n_col, figsize=(12, 8))
# set the background color of the figure
fig.set_facecolor('#1d2b3a')

# Loop through each ticker and plot the data
for i, ticker in enumerate(tickers):
    chart_data = data[data['Ticker']==ticker][-7:]  # select last 7 rows of data for each ticker
    row = i // 2
    column = i % 2

    ax = axes[row][column]  
    ax.plot(chart_data["Date"], chart_data["Low"], color=colors[i], linewidth=2, marker='o')  # plot the data with specified color, label, and marker
    
    # set y-axis label
    ax.set_ylabel("Closing Price")

    # set subplot title
    ax.set_title(f"{ticker}")

    # enable girdline
    ax.grid(True, color='#c2c2c2')

    # change label color to white
    ax.title.set_color('white')
    ax.yaxis.label.set_color('white')
    ax.tick_params(axis='both', colors='white') 

    # rotate x-axis labels
    ax.tick_params(axis='x', rotation=45)

    # increase the y range
    ax.set_ylim(int(chart_data['Low'].min() * 0.95), int(chart_data['Low'].max() * 1.05))  # set y-axis limits

    # add labels to data points
    for date_label, price_low in zip(chart_data['Date'], chart_data['Low']):
        ax.text(date_label, price_low, f'{price_low:.2f}', ha='center', va='bottom', color='black')
        
plt.tight_layout()
plt.show()