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()
Asked
Active
Viewed 305 times
0

Scott Boston
- 147,308
- 15
- 139
- 187

greenteacooler
- 1
- 2
-
1Do you have some example data? – Ruthger Righart Nov 22 '20 at 20:14
-
I'm actually just pulling it straight from yahoo, I couldn't give you an example – greenteacooler Nov 22 '20 at 20:15
-
Does this answer your question? [Change tick frequency on X (time, not number) frequency in matplotlib](https://stackoverflow.com/questions/25538520/change-tick-frequency-on-x-time-not-number-frequency-in-matplotlib) – JAV Nov 22 '20 at 20:21
1 Answers
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()

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