Using matplotlib to annotate certain points

matplotlib, python

Solution

You can do it like this:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
data = (0, 2, 3, 5, 5, 5, 9, 7, 8, 6, 6)
ax.plot(data, 'r-', linewidth=4)

plt.axvline(x=5, ymin=0, ymax=4.0 / max(data), linewidth=4)
plt.text(5, 4, 'your text here')
plt.show()

Note, that somewhat strangely the `ymin` and `ymax` values run from `0 to 1`, so require normalising to the axis

EDIT: The OP has modified the code to make it more OO:

fig = plt.figure()
data = (0, 2, 3, 5, 5, 5, 9, 7, 8, 6, 6)

ax = fig.add_subplot(1, 1, 1)
ax.plot(data, 'r-', linewidth=4)
ax.axvline(x=5, ymin=0, ymax=4.0 / max(data), linewidth=4)
ax.text(5, 4, 'your text here')
fig.show()

Problem

While I can hack together code to draw an XY plot, I want some additional stuff: - Vertical lines that extend from the X axis to a specified distance upward - text to annotate that point, proximity is a must (see the red text) - the graph to be self-contained image: a 800-long sequence should occupy 800 pixels in width (I want it to align with a particular image as it is an intensity plot) How do I make such a graph in mathplotlib?

Original source