【问题标题】:matplotlib coordinates format [duplicate]matplotlib坐标格式[重复]
【发布时间】:2013-01-17 22:26:29
【问题描述】:

我有这样的简单情节:

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()

但是当您在图形上移动或按住光标时,绘图窗口右下角显示的坐标看起来像 6.43953e + 06。
如何让我的输入坐标按原样显示,例如
6439518.298 代替 6.43953e + 0
?
提前致谢

【问题讨论】:

    标签: python matplotlib coordinates


    【解决方案1】:

    ax.fmt_xdata 属性可以设置为格式化显示字符串的函数。

    例如:

    ax.fmt_xdata = lambda x: "{0:f}".format(x)
    ax.fmt_ydata = lambda x: "{0:f}".format(x)
    

    【讨论】:

    • 谢谢,这正是我想要的。
    • 但还有一个问题:当您检查我的代码时,您会看到我将坐标轴交换为 x, y 作为 y, x 到 matplotlib 以使我的绘图朝北。结果我的坐标反向显示在绘图窗口中。可以轻松更改吗?
    【解决方案2】:

    你也可以通过设置format_coord来完全覆盖默认标签

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

    example, api doc

    【讨论】:

    • 谢谢很多,这是一个很棒的提示,这将让我在此问题上获得我需要的一切。 span>
    猜你喜欢
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多