Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib coordinates format [duplicate]

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

like image 867
daikini Avatar asked Feb 02 '13 20:02

daikini


2 Answers

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)
like image 122
grep Avatar answered Nov 09 '22 09:11

grep


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

like image 8
tacaswell Avatar answered Nov 09 '22 09:11

tacaswell