【发布时间】:2016-02-08 22:11:36
【问题描述】:
当您使用 imshow 在窗口的右下角绘制图像时,会显示光标的坐标。但是,当我尝试设置轴的刻度和刻度标签时,窗口停止显示坐标,只显示“x= y="
小例子:
import matplotlib.pyplot as plt
import numpy as np
d = np.random.rand(100, 100)
fig = plt.figure()
ax = plt.gca()
plt.imshow(d)
# If I comment this I get coordinates in the bottom right,
# but after setting the ticks I only get "x= y="
ax.set_xticks([0, 25, 50, 75, 100])
ax.set_xticklabels([0, 0.25, 0.5, 0.75, 1])
ax.set_yticks([0, 25, 50, 75, 100])
ax.set_yticklabels([0, 0.25, 0.5, 0.75, 1])
fig.show()
raw_input()
这会显示一个随机的数据图并将刻度标签设置为从 0 到 1,但右下角的光标坐标仅显示“x= y=”。
有没有办法让坐标以刻度定义的新单位显示?我认为这与设置轴的变换有关,但我无法弄清楚。
【问题讨论】:
标签: python python-2.7 matplotlib imshow