I want to have the x-tick date labels centered between the tick marks, instead of centered about the tick marks as shown in the photo below.
I have read the documentation but to no avail - does anyone know a way to do this?
Here is everything that I've used for my x-axis tick formatting if it helps:
day_fmt = '%d'
myFmt = mdates.DateFormatter(day_fmt)
for tick in ax.xaxis.get_major_ticks():
One way to do it is to use the minor ticks. The idea is that you set the minor ticks so that they are located halfway between the major ticks, and you manually specify the labels.
import matplotlib.ticker as ticker # a is an axes object, from figure.get_axes() # Hide major tick labels a.xaxis.set_major_formatter(ticker.NullFormatter()) # Customize minor tick labels a.xaxis.set_minor_locator(ticker.FixedLocator([1.5,2.5,3.5,4.5,5.5])) a.xaxis.set_minor_formatter(ticker.FixedFormatter(['1','2','3','4','5']))
The three lines:
This is just a simple example. You would probably want to streamline it a bit by populating the lists in a loop or something.
You can also experiment with other locators or formatters.
EDIT : Examples