Show the final y-axis value of each row with matplotlib

I am drawing a graph with some lines using matplotlib, and I want to display the final value ynext to where each line ends on the right side as follows: enter image description here

Any solutions or pointers to the relevant parts of the API? I am very puzzled.

I am using matplotlib 1.0.0 and the pyplot interface, for example. pyplot.plot(xs, ys, f, xs_, ys_, f_).

+5
source share
3 answers

Option 1 - pyplot.text

pyplot.text(x, y, string, fontdict=None, withdash=False, **kwargs)

Option 2 . Use other axes :

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
+4
source

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()

enter image description here

8 y . .. . http://matplotlib.sourceforge.net/users/annotations_guide.html ( , , y. va='center'.)

, , .. ..

+10

. . , y [-1]. .

gbm = np.log(np.cumsum(np.random.randn(10000))+10000)
plt.plot(gbm)
plt.annotate('%0.2f' % gbm[-1], xy=(1, gbm[-1]), xytext=(8, 0), 
             xycoords=('axes fraction', 'data'), textcoords='offset points')
plt.axhline(y=gbm[-1], color='y', linestyle='-.')
plt.show()

y.

+1

All Articles