matplotlib coordinates format [duplicate]

心不动则不痛 提交于 2019-12-19 07:08:06

问题


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


回答1:


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)



回答2:


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



来源:https://stackoverflow.com/questions/14666114/matplotlib-coordinates-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!