Created
March 8, 2018 12:16
-
-
Save cpelley/6371a16c4ac56527b81873c370f70159 to your computer and use it in GitHub Desktop.
Show coordinates under cursor for iris
This file contains 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
... | |
iplt.pcolormesh(cube) | |
# https://matplotlib.org/gallery/api/image_zcoord.html | |
numrows, numcols = cube.shape | |
def format_coord(x, y): | |
#col = int(x + 0.5) | |
#row = int(y + 0.5) | |
row = int(abs(cube.coord(axis='y').points - y).argmin()) | |
col = int(abs(cube.coord(axis='x').points - x).argmin()) | |
if col >= 0 and col < numcols and row >= 0 and row < numrows: | |
z = cube.data[row, col] | |
return 'x=%1.4f, y=%1.4f, z=%1.4f (row:%i, col:%i)' % (x, y, z, row, col) | |
else: | |
return 'x=%1.4f, y=%1.4f' % (x, y) | |
iplt.plt.gca().format_coord = format_coord | |
iplt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment