Skip to content

Instantly share code, notes, and snippets.

@blaylockbk
Last active March 30, 2018 14:47
Show Gist options
  • Save blaylockbk/4f8c26f2da59ea85c95d3a55df754d07 to your computer and use it in GitHub Desktop.
Save blaylockbk/4f8c26f2da59ea85c95d3a55df754d07 to your computer and use it in GitHub Desktop.
formating datetime on axis
# Method 1: when you are using plt
from matplotlib.dates import DateFormatter
formatter = DateFormatter('%Y-%m-%d %H:%M:%S')
plt.gcf().axes[0].xaxis.set_major_formatter(formatter)
# Method 2: when you have already axessed the axes
from matplotlib.dates import DateFormatter
formatter = DateFormatter('%Y-%m-%d %H:%M:%S')
ax1.xaxis.set_major_formatter(formatter)
# Hour locator
import matplotlib.dates as mdates
xaxis.set_major_locator(mdates.HourLocator(range(0, 24, 3)))
ax1.xaxis.set_minor_locator(mdates.HourLocator(range(0, 24, 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment