0

my purpose is to create an anomaly graph for a stock that have dates and close. I tried to create outliers, but I get the lines not in the place I want. For example, I want the line to be in the year of 2019 and after 2020 where there are drastic changes. The X line has dates and the problem I don't know how to write the outliers

I thought to write y["2019"]=40 for example but it doesn't do anything enter image description here


from pandas import read_csv
from matplotlib import pyplot
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
#from IPython.core.debugger import set_trace

#import data

AAPL= pd.read_csv('AAPL.csv', header=0, squeeze=True)
x=AAPL['Date']
x=pd.to_datetime(x)
y=AAPL['Close/Last']
plt.figure(figsize=(15,7))
plt.plot(x, y, label="Close")
plt.title("AAPL")
plt.xlabel("Time")
plt.ylabel("Close")
plt.xticks(rotation=0)
plt.grid()
plt.show()

y[5] = 5
y[60] =55
y[85] = 1.4
n_outliers = 3


plt.figure(figsize=(15,7))
plt.plot(x,y)
plt.scatter(x,y)
plt.grid()
plt.ylabel('Y')
plt.xlabel('x')
plt.show()

Thank you in advance

Bordento22
  • 37
  • 1
  • 5
  • Are you looking for a vertical line at a datetime? – Trenton McKinney Nov 05 '21 at 13:24
  • Does this answer your question? [How to draw vertical lines on a given plot in matplotlib](https://stackoverflow.com/q/24988448/7758804) and the bottom of this [answer](https://stackoverflow.com/a/64035939/7758804) – Trenton McKinney Nov 05 '21 at 13:25

0 Answers0