I make a simple scraper for a company's stock price history. The problem I have is when I use matplotlib to make graph, most of the x-axis labels (date in this case) are missing. How can I force pandas/matplotlib to display all labels?
import pandas as pd
import urllib.request
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
#open url and make soup
quote_url = "http://www.nasdaq.com/symbol/atnx/historical"
page = urllib.request.urlopen(quote_url)
soup = BeautifulSoup(page, 'html.parser')
#grab all the stock price data (except volume) for the last 2 weeks
trs = soup.find('div', attrs={'id': 'historicalContainer'})\
.find('tbody').find_all('tr')
temp_list = list()
for tr in trs:
for td in tr:
if td.string.strip():
temp_list.append(td.string.strip())
list_of_list = [temp_list[i:i+5] for i in range(0, len(temp_list), 6)]
#only take data from the last 2 weeks for the sake of simplicity
list_of_list = list_of_list[:14]
data_dict = {sublist[0]: [float(n.replace(',', '')) for n in sublist[1:len(sublist)]] for sublist in list_of_list}
#create a pandas DataFrame for stock prices
df = pd.DataFrame(data_dict)
df.rename({0: 'Open', 1: 'High', 2: 'Low', 3: 'Close/Last'}, inplace=True)
#Transpose dataframe
df= df.T
#plot with matplotlib (most x labels are missing here)
df.plot()
plt.show()
Thanks.