import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook

datafile = cbook.get_sample_data('goog.npy')
try:
    r = np.load(datafile, encoding='bytes').view(np.recarray)

except:
    r = np.load(datafile).view(np.recarray)

fig, ax = plt.subplots()
ax.plot(r.date, r.adj_close)

# format the ticks
years = mdates.YearLocator()   # every year
months = mdates.MonthLocator()  # every month
yearsFmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)

datemin = datetime.date(r.date.min().year, 1, 1)
datemax = datetime.date(r.date.min().year + 1, 1, 1)
ax.set_xlim(datemin, datemax)


plt.show()
2affb289abf39dc81b014c6b38c175e2c5d524f7
<mask token>

<mask token>
try:
    r = np.load(datafile, encoding='bytes').view(np.recarray)
except:
    r = np.load(datafile).view(np.recarray)
<mask token>
ax.plot(r.date, r.adj_close)
<mask token>
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)
<mask token>
ax.set_xlim(datemin, datemax)
plt.show()

<mask token>
datafile = cbook.get_sample_data('goog.npy')
try:
    r = np.load(datafile, encoding='bytes').view(np.recarray)
except:
    r = np.load(datafile).view(np.recarray)
fig, ax = plt.subplots()
ax.plot(r.date, r.adj_close)
years = mdates.YearLocator()
months = mdates.MonthLocator()
yearsFmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)
datemin = datetime.date(r.date.min().year, 1, 1)
datemax = datetime.date(r.date.min().year + 1, 1, 1)
ax.set_xlim(datemin, datemax)
plt.show()

import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook
datafile = cbook.get_sample_data('goog.npy')
try:
    r = np.load(datafile, encoding='bytes').view(np.recarray)
except:
    r = np.load(datafile).view(np.recarray)
fig, ax = plt.subplots()
ax.plot(r.date, r.adj_close)
years = mdates.YearLocator()
months = mdates.MonthLocator()
yearsFmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)
datemin = datetime.date(r.date.min().year, 1, 1)
datemax = datetime.date(r.date.min().year + 1, 1, 1)
ax.set_xlim(datemin, datemax)
plt.show()

import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook

datafile = cbook.get_sample_data('goog.npy')
try:
    r = np.load(datafile, encoding='bytes').view(np.recarray)

except:
    r = np.load(datafile).view(np.recarray)

fig, ax = plt.subplots()
ax.plot(r.date, r.adj_close)

# format the ticks
years = mdates.YearLocator()   # every year
months = mdates.MonthLocator()  # every month
yearsFmt = mdates.DateFormatter('%Y')
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)

datemin = datetime.date(r.date.min().year, 1, 1)
datemax = datetime.date(r.date.min().year + 1, 1, 1)
ax.set_xlim(datemin, datemax)


plt.show()