0
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader as web

#This makes a chart w/3 hour intervals and I would need something like 30 minutes
style.use("ggplot")
start = dt.datetime(2019,4,24)
end = dt.datetime(2019,5,25)
df = web.get_data_yahoo("TSLA", start, end)
df["Adj Close"].plot()
plt.title('Tesla Price v. First Quarter Earnings 2019')
plt.ylabel('USD')
plt.show()
Scott Boston
  • 147,308
  • 15
  • 139
  • 187

1 Answers1

0

The following example shows how to set the primary scale at 7-day intervals and hide the secondary scale as an example. Other variations can be found on formatter page and Locator page.

import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib import style
import pandas as pd
import pandas_datareader as web

fig, ax = plt.subplots()
#This makes a chart w/3 hour intervals and I would need something like 30 minutes
style.use("ggplot")
start = dt.datetime(2019,4,24)
end = dt.datetime(2019,5,25)
df = web.get_data_yahoo("TSLA", start, end)

ax = df["Adj Close"].plot()
days = mdates.DayLocator(interval=7)
days_fmt = mdates.DateFormatter('%m/%d')
ax.xaxis.set_major_locator(days)
ax.xaxis.set_major_formatter(days_fmt)
ax.minorticks_off()

plt.title('Tesla Price v. First Quarter Earnings 2019')
plt.ylabel('USD')
plt.show()

enter image description here

r-beginners
  • 31,170
  • 3
  • 14
  • 32