Reputation: 23078
While I can hack together code to draw an XY plot, I want some additional stuff:
How do I make such a graph in mathplotlib?
Upvotes: 4
Views: 7741
Reputation: 35269
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()
Upvotes: 7