7

I have simple plot like this:

matplotlib.pyplot as plt

pt_no = [1,2,3]
coord_x = [6035763.111, 6035765.251, 6035762.801]
coord_y = [6439524.100, 6439522.251, 6439518.298]

fig, ax = plt.subplots()
ax.scatter(coord_y, coord_x, marker='x')
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
for i, txt in enumerate(pt_no):
    ax.annotate(txt, (coord_y[i], coord_x[i]))

plt.show()

but coordinates displayed in bootom-right corner of plot window as you move or hold cursor over the figure look like 6.43953e + 06.
How can I have my input coordinates displayed exactly as-is, for example
6439518.298 instead 6.43953e + 0
?
Thanks in advance

daikini
  • 1,307
  • 6
  • 23
  • 36

2 Answers2

10

The ax.fmt_xdata attribute can be set to a function that formats the displayed string.

For example:

ax.fmt_xdata = lambda x: "{0:f}".format(x)
ax.fmt_ydata = lambda x: "{0:f}".format(x)
grep
  • 726
  • 7
  • 13
  • But one more question: As you examine my code you'll see I swapped axes passing my coordinate x, y as y, x to matplotlib to make my plot north-oriented. As result my coords are inversely displayed in plot window. Can it be easily changed? – daikini Feb 02 '13 at 21:19
8

You can also completely override the default labeling by setting format_coord

ax.format_coord = lambda x, y: "({0:f}, ".format(y) +  "{0:f})".format(x)

example, api doc

tacaswell
  • 84,579
  • 22
  • 210
  • 199