How to show yticks on the plot/graph (not on y-axis). Show yticks near points
<p>I have a plot with a simple line. For the moment, I set <strong>yticks</strong> as invisible.
<a href="http://i.stack.imgur.com/EaW9w.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/EaW9w.jpg" alt="enter image description here"></a></p>

<p>Here is the code for the graph:</p>

<pre><code>import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 1.5, 2, 2.5, 3]

fig, ax = plt.subplots(figsize=(15,10))
plt.plot(x, y, 'ko-')

plt.xlabel('X', fontsize=15)
plt.ylabel('Y', fontsize=15)
plt.xticks(x, fontsize=13)
plt.yticks(y, visible=False)

plt.margins(0.1, 0.1)
plt.title('Graph', color='black', fontsize=17) 
ax.axis('scaled') 
ax.grid()
plt.show()
</code></pre>

<hr>

<p>I need to show/print <strong>yticks</strong> right on the graph itself (not on the left side). So, <strong>yticks</strong> are alongside with datapoints.</p>

<p><strong>Desired output:</strong>
<a href="http://i.stack.imgur.com/vvfCm.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/vvfCm.jpg" alt="enter image description here"></a></p>

<hr>

<p>How to do it with <strong>Matplotlib</strong>?</p>

<p>You can use <code>plt.text()</code> to annotate text onto an axis. By iterating over your x,y points you can place a label at each marker. For example: </p>

<pre><code>import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 1.5, 2, 2.5, 3]

fig, ax = plt.subplots(figsize=(15,10))
plt.plot(x, y, 'ko-')

plt.xlabel('X', fontsize=15)
plt.ylabel('Y', fontsize=15)
plt.xticks(x, fontsize=13)
plt.yticks(y, visible=False)

offset = 0.05
for xp, yp in zip(x,y):
    label = "%s" % yp
    plt.text(xp-offset, yp+offset, label, fontsize=12, horizontalalignment='right')

plt.margins(0.1, 0.1)
plt.title('Graph', color='black', fontsize=17) 
ax.axis('scaled') 
ax.grid()
plt.show()
</code></pre>

<p>Gives the following figure:</p>

<p><a href="https://i.stack.imgur.com/dDP6C.png" rel="nofollow"><img src="https://i.stack.imgur.com/dDP6C.png" alt="enter image description here"></a></p>

python matplotlib linechart