Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change format of coordinate text in status bar

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

like image 249
A.Ezkie Avatar asked Mar 14 '23 02:03

A.Ezkie


1 Answers

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

like image 196
tmdavison Avatar answered Mar 16 '23 05:03

tmdavison