Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have been trying to set a minor DateTime interval on the x-axis but it doesn't show at all. I am doing this on google collabnote book. I was able to get it to work before then re-run it seems to produce a different result far from the right plot. Any suggestion would be great, thank you in advance.
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
plt.style.use("dark_background")
eurusd['Close'] = pd.to_numeric(eurusd['Close'])
plt.figure(figsize=(40,10))
plt.xticks(rotation= 90)
ax = plt.gca()
xfmt = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
hours= mdates.HourLocator(interval=180)
ax.xaxis.set_major_formatter(xfmt)
ax.xaxis.set_major_locator(mdates.HourLocator(interval=720))
#issues with the minor locator not reflecting on plot
ax.xaxis.set_minor_locator(hours)
ax.spines['bottom'].set_linewidth(0.5)
plt.plot(eurusd['Local time'],eurusd['Close'],color='yellow', linewidth=1.5)
The minor scale must be set in the same way as the major scale.
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
plt.style.use("dark_background")
eurusd['Close'] = pd.to_numeric(eurusd['Close'])
plt.figure(figsize=(20,10))
# plt.xticks(rotation= 90)
ax = plt.gca()
xfmt = mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
hours= mdates.HourLocator(interval=180)
ax.xaxis.set_major_formatter(xfmt)
ax.xaxis.set_major_locator(mdates.HourLocator(interval=720))
#issues with the minor locator not reflecting on plot
ax.xaxis.set_minor_formatter(xfmt)
ax.xaxis.set_minor_locator(hours)
ax.spines['bottom'].set_linewidth(0.5)
plt.plot(eurusd['Local_time'], eurusd['Close'], color='yellow', linewidth=1.5)
plt.setp(ax.xaxis.get_majorticklabels(), rotation=45)
plt.setp(ax.xaxis.get_minorticklabels(), rotation=45)
plt.show()
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.