我正在尝试使用Matplotlib创建散点图,并希望反转轴的刻度标签(而不是轴本身)。我知道PercentFormatter(),但似乎没有一种方法可以在调用它之后反转标记。
我尝试手动设置刻度,将最大Y轴值的反转百分比值列表如下:
import matplotlib.pyplot as plt
positions = [
[4, 20, 12, 5],
[1, 10, 2, 9],
[8, 100, 40, 7],
[0, 15, 5, 3]
]
line_pos = 8
for line, len_line, g, t in positions:
gRel = g/len_line
tRel = t/len_line
pos = line_pos - line
plt.plot([gRel, gRel +tRel], [pos, pos])
l = [(j/line_pos)*100 for j in reversed(range(0, line_pos))]
locs, labels = plt.yticks()
plt.yticks(locs, l)
plt.show()
但有些标记出现在刻度界限之外。
如何使用每个刻度标签的正确百分比来正确地反转这些标签?
提前感谢您的回答。
发布于 2019-08-07 14:30:08
看起来这更像你想要的:
import matplotlib.pyplot as plt
positions = [
[4, 20, 12, 5],
[1, 10, 2, 9],
[8, 100, 40, 7],
[0, 15, 5, 3]
]
line_pos = 8
for line, len_line, g, t in positions:
gRel = g/len_line
tRel = t/len_line
pos = line_pos - line
plt.plot([gRel, gRel +tRel], [pos, pos])
locs = list(range(line_pos+1))
l = [(j/line_pos)*100 for j in reversed(locs)]
plt.yticks(locs, l)
plt.show()
https://stackoverflow.com/questions/57392705
复制相似问题