4

Does anyone know how to modify the "x" and "y" in the status bar below a plot?

I want to change it to "Longitude" and "Latitude", is it possible in matplotlib?

enter image description here

tmdavison
  • 64,360
  • 12
  • 187
  • 165
A.Ezkie
  • 51
  • 5
  • Does this answer your question? [Interactive pixel information of an image in Python?](https://stackoverflow.com/questions/27704490/interactive-pixel-information-of-an-image-in-python) – Bas Swinckels Aug 17 '20 at 08:54

1 Answers1

7

You can re-assign the format_coord method of your Axes, as in the following example (adapted from here and here):

import matplotlib.pyplot as plt
import numpy as np

fig,ax = plt.subplots(1)

ax.pcolormesh(np.random.rand(20,20))

def format_coord(x, y):
    return 'Longitude={:6.3f}, Latitude={:6.3f}'.format(x, y)

ax.format_coord = format_coord

plt.show()

Or, in a one-liner, you could use a lambda function:

ax.format_coord = lambda x, y: "Longitude={:6.3f}, Latitude={:6.3f}".format(x,y)

enter image description here

Community
  • 1
  • 1
tmdavison
  • 64,360
  • 12
  • 187
  • 165