0

This produces a graph of all these stock prices plotted against the date. If you zoom in, all the tiny ticks have labels for the dates. I wanted to reduce the frequency of ticks so that it only displayed tick marks at the month and year. I have tried using locators and formatters, but whenever I add them all of the ticks and tick labels completely disappear. All that's left at the x-axis is the x-axis label.

Does any of the issue lie within the fact that I extract the date and use that for the x-axis plot for every new batch of stock prices I want to plot? Any advice would be appreciated. I am a beginner programmer.

from iexfinance import get_historical_data
import pandas as pd
import matplotlib.pyplot as plt

def tester():
    start_date = '20170828'
    end_date = '20180828'
    symbols =['GOOG', 'IBM', 'CRON']

    for symbol in symbols:
        f_temp = get_historical_data(symbol, start_date, end_date, output_format='pandas')
        df_close = pd.DataFrame(f_temp['close'])
        df_open = pd.DataFrame(f_temp['open'])
        df_date_string = 
        pd.to_datetime(f_temp.index).strftime("%Y%m%d").astype(str)

        df = pd.merge(df_open, df_close, on=df_date_string)
        df.columns = ['date', 'open', 'close']
        plt.legend(symbols)
        plot_data(df)
    plt.show()
    return df

def normalize_data(df):
    return df/df.ix[0, :]

def plot_data(df):
    normalized = normalize_data(df['close'])
    plt.plot(df['date'], normalized)

    plt.title("Normalized close stock prices")
    plt.xlabel("Dates")
    plt.ylabel("Close prices")
    plt.tight_layout()

if __name__ == "__main__":
    df = tester()
Harry Cutts
  • 1,352
  • 11
  • 25
  • Possible duplicate of [datetime x-axis matplotlib labels causing uncontrolled overlap](https://stackoverflow.com/questions/49231052/datetime-x-axis-matplotlib-labels-causing-uncontrolled-overlap) – wwii Sep 12 '18 at 17:38
  • More dupes: https://stackoverflow.com/q/26700598/2823755, https://stackoverflow.com/q/41812646/2823755, https://stackoverflow.com/q/13515471/2823755, ........ – wwii Sep 12 '18 at 17:40

0 Answers0