import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
import datetime
def plot_coords(filename):
df = pd.read_csv(filename, header=None)
plt.plot(df[0],df[1],'.')
plot_coords('coordinates_3.txt')
plot_coords('regression_coordinates_1.txt')
def plot_linear_regression(filename):
df = pd.read_csv(
filename, header=None
)
m, b = np.polyfit(df[0], df[1], deg=1)
line_x = np.arange(df[0].min(), df[0].max(), 0.5)
line_y = m * line_x + b
plot_coords(filename)
plt.plot(line_x, line_y)
plot_linear_regression('regression_coordinates_1.txt')
def read_and_plot(filename):
df = pd.read_csv(filename)
df['Low'] = df['Low'].str.replace('$', '').astype(float)
df['Date'] = pd.to_datetime(df['Date'], format='%m/%d/%Y')
plt.plot(df['Date'], df['Low'])
plt.xlabel('Time')
plt.ylabel('Low')
read_and_plot('AAPL_5Y.csv')
read_and_plot('GME_5Y.csv')
plt.title('AAPL vs. GME 5Y')
plt.legend(['AAPL', 'GME'])
<matplotlib.legend.Legend at 0x28705d07190>