Also consider using extent (doc) so that matplotlib about how to place label tags and add an arbitrary shift:
data = np.array([range(10),range(10,20)]) fig = plt.figure(figsize=(3,5)) ax = fig.add_subplot(111) ax.imshow(data,aspect='auto',extent=[10000,10010,0,1])
If you definitely want to do this on my part, you might be better off setting the formatter and locator axis to get what you want (doc) .
import matplotlib.pyplot as plt import numpy as np def scale_xaxis(number): return(number+1001) def my_form(x,pos): return '%d'%scale_xaxis(x) data = np.array([range(10),range(10,20)]) fig = plt.figure(figsize=(3,5)) ax = fig.add_subplot(111) ax.imshow(data,aspect='auto') ax.autoscale(False) ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(int(2))) ax.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(my_form))
The locator must be configured to make sure that ticks do not fit into non-integer locations, which are then force converted to integers by formatting (which would leave them in the wrong place)
related issues:
matplotlib: format axis offset to integers or a specific number
remove lead 0 from matplotlib tag label format
tacaswell
source share