Created
October 24, 2012 03:35
-
-
Save lebedov/3943521 to your computer and use it in GitHub Desktop.
How to replace tick labels for an image displayed with matplotlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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