Skip to content

Instantly share code, notes, and snippets.

@lebedov
Created October 24, 2012 03:35
Show Gist options
  • Select an option

  • Save lebedov/3943521 to your computer and use it in GitHub Desktop.

Select an option

Save lebedov/3943521 to your computer and use it in GitHub Desktop.
How to replace tick labels for an image displayed with matplotlib
#!/usr/bin/env python
"""
Demonstrate how to replace tick labels for a displayed image.
"""
import numpy as np
import pylab as pl
im = np.random.rand(100, 200)
pl.imshow(im, origin='lower')
x = np.linspace(0, 1000, len(pl.xticks()[0]-1))
y = np.linspace(5, 2500, len(pl.yticks()[0]-1))
# Discard the first location because it's label is empty:
locs, labels = pl.xticks()
pl.xticks(locs[1:], map(lambda f: '%3.2e' % f, x))
locs, labels = pl.yticks()
pl.yticks(locs[1:], map(lambda f: '%3.2e' % f, y))
pl.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment