matplotlib coordinates format [duplicate]

2020-03-19 06:43发布

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

2条回答
Fickle 薄情
2楼-- · 2020-03-19 07:07

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)
查看更多
Root(大扎)
3楼-- · 2020-03-19 07:21

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

查看更多
登录 后发表回答