Show the final y-axis value of each line with matplotlib
我正在使用 matplotlib 绘制带有一些线的图形,我想在每条线在右侧结束的位置旁边显示最终的
有任何解决方案或指向 API 相关部分的指针吗?我很困惑。
我正在使用 matplotlib 1.0.0 和 pyplot 接口,例如
虽然 Ofri 的回答没有任何问题,但
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import matplotlib.pyplot as plt import numpy as np x = np.arange(61).astype(np.float) plt.plot(x, y1) for var in (y1, y2): plt.show() |
这会将文本 8 点放置在轴右侧的右侧,即每个图的最大 y 值处。您还可以添加箭头等。请参阅 http://matplotlib.sourceforge.net/users/annotations_guide.html (如果您希望文本垂直居中于给定的 y 值,您也可以更改垂直对齐方式。只需指定
此外,这不依赖于刻度位置,因此它可以完美地用于日志图等。根据轴边界的位置及其偏移量给出文本的位置有很多如果您开始重新调整绘图等的优势。
选项 1 – pyplot.text
1 | pyplot.text(x, y, string, fontdict=None, withdash=False, **kwargs) |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/267876.html