如何在matplotlib中操纵y轴?

时间:2017-04-12 14:52:53

标签: python matplotlib axis-labels

我在matplotlib中显示一个比率

plt.plot(datax, datay, style, color=colour)

但是,我希望1下方的数据显示为2-1/y。例如:值为2的数据点应显示在2,值1显示在1,但值1/2应显示在0 {1}}的值为1/3,其中-11/4-2等等。但是,我希望标签显示数据点的实际值。

1 个答案:

答案 0 :(得分:0)

假设您使用散点图并且datay是一个numpy数组,您可以构建另一个新的Y坐标数组:

datay1 = np.where(datay < 1, 2 - 1 / datay, datay)

然后在新位置绘制数据点,但用旧标签注释它们:

plt.scatter(datax, datay1)
for x,y,y1 in zip(datax, datay, datay1):
    plt.annotate("%.f" % y, xy=(x,y1))