Using matplotlib to comment on specific points

While I can crack the code to draw the XY graph, I need some extra material:

  • Vertical lines that extend from the X axis to a given distance up
  • text to annotate this point; proximity is mandatory (see red text).
  • the graph should be self-sufficient: the 800-long sequence should occupy 800 pixels in width (I want it to align with a certain image, since this is a plot of intensity)

enter image description here

How to create such a chart in mathplotlib?

+3
source share
2 answers

You can do it as follows:

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

, ymin ymax 0 to 1,

enter image description here


EDIT: OP , 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()
+7

All Articles