Issue
The following code gives me a graph of apple's stock price, but it's missing the last label.
import numpy as np
import matplotlib.pyplot as plt
from random import random
import statsmodels.api as sm
import pandas as pd
from matplotlib.ticker import MaxNLocator
data = pd.read_csv('data_assign_p3-1.csv')
fig, axes = plt.subplots(1, 1)
axes.plot(data['DATE'], data['APPLE'])
axes.xaxis.set_major_locator(MaxNLocator(4))
fig.suptitle('Apple')
plt.show()
Solution
I was able to replicate your problem. Please check the start and end dates for which you are picking up the data. It looks like you are using 13-02-2007
as the start date of around 20-01-2013
. Downloading the same data from Yahoo Finance has no entry from 18th-22nd. As you have not converted the data into datetime, python thinks these are categorical values and misses that date. Convert the column to Datetime and, if required, format the output x-axis dates as below. I was able to get it to work with these changes. Hope this helps.
from random import random
import statsmodels.api as sm
import pandas as pd
from matplotlib.ticker import MaxNLocator
data = pd.read_csv('AAPL.csv')
data['DATE'] = pd.to_datetime(data['DATE'], format='%d-%m-%Y') ##Convert
fig, axes = plt.subplots(1, 1)
axes.plot(data['DATE'], data['APPLE'])
axes.xaxis.set_major_locator(MaxNLocator(4))
import matplotlib.dates as mdates
axes.xaxis.set_major_formatter(mdates.DateFormatter('%d-%m-%Y'))
fig.suptitle('Apple')
plt.show()
Answered By - Redox
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.