我正在使用matplotlib绘制一些带有一些线条的图形,我想y在右边的每一行结束的位置显示最终值,如下所示:

API的相关部分的任何解决方案或指针?我很难过.
我正在使用matplotlib 1.0.0和pyplot接口,例如pyplot.plot(xs, ys, f, xs_, ys_, f_).
Joe*_*ton 15
虽然Ofri的答案没有任何问题,但annotate特别是为此目的:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(61).astype(np.float)
y1 = np.exp(0.1 * x)
y2 = np.exp(0.09 * x)
plt.plot(x, y1)
plt.plot(x, y2)
for var in (y1, y2):
plt.annotate('%0.2f' % var.max(), xy=(1, var.max()), xytext=(8, 0),
xycoords=('axes fraction', 'data'), textcoords='offset points')
plt.show()
Run Code Online (Sandbox Code Playgroud)

这将文本8 点放在轴右侧的右侧,每个图的最大y值.您还可以添加箭头等.请参阅http://matplotlib.sourceforge.net/users/annotations_guide.html (如果您希望文本垂直居中于给定的y值,也可以更改垂直对齐.只需指定va='center'.)
此外,这不依赖于刻度位置,因此它可以完美地用于对数图等.如果您开始,根据轴边界的位置及其在点的偏移量给出文本的位置具有很多优点重新调整情节等
选项1 - pyplot.text
pyplot.text(x, y, string, fontdict=None, withdash=False, **kwargs)
Run Code Online (Sandbox Code Playgroud)
选项2-使用第二个轴:
second_axes = pyplot.twinx() # create the second axes, sharing x-axis
second_axis.set_yticks([0.2,0.4]) # list of your y values
pyplot.show() # update the figure
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6399 次 |
| 最近记录: |