How do I take this code:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x=[1,2,3,4,5,6,7,8,9,10]
y=[1,1,1,2,10,2,1,1,1,1]
line, = ax.plot(x, y)
ymax = max(y)
xpos = y.index(ymax)
xmax = x[xpos]
arrow = ax.annotate('local max:' + str(ymax), xy=(xmax, ymax), xytext=(xmax, ymax + 2),
arrowprops=dict(arrowstyle = '-', connectionstyle = 'arc3',facecolor='red'))
#==============================================================================
# arrow.remove()
#==============================================================================
ax.set_ylim(0,20)
plt.show()
and create a circular marker (Point) instead of an arrow. I would like to Keep the text of the arrow though.
If you only want a dot and text with no arrow/line connecting to the dot, you can simply do so using the text
function:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x=[1,2,3,4,5,6,7,8,9,10]
y=[1,1,1,2,10,2,1,1,1,1]
line, = ax.plot(x, y)
ymax = max(y)
xpos = y.index(ymax)
xmax = x[xpos]
# Add dot and corresponding text
ax.plot(xmax, ymax, 'ro')
ax.text(xmax, ymax+2, 'local max:' + str(ymax))
ax.set_ylim(0,20)
plt.show()
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With