-1

I have a plot that looks like this: enter image description here

I plot those arrows using the annotate method

ax.annotate('sample events', (x_value, y_value), xytext=(x_value, -3000), rotation=90, va='top', arrowprops = {'width': 2, 'headwidth': 4, 'linestyle': '--'})

but what I want is something like: enter image description here

and it's better if the annotation text is on the x-axis, is there any way to do it?

(I've tried ax.axvline(x=x_value) but it makes vertical lines across the whole plot)

1

2 Answers 2

1

The easy method is to use ax.stem, for example:

import matplotlib.pyplot as plt
import numpy as np

y = np.random.random(20)

fig, ax = plt.subplots()
ax.plot(y)
ax.stem(y, markerfmt='.')
plt.show()

Resulting example plot is:

enter image description here

If You want to hide horizontal line, then use basefmt = " ":

ax.stem(y, basefmt = " ", markerfmt='.')
Sign up to request clarification or add additional context in comments.

Comments

0

At first: You should avoid # within your code, since it will then be interpreted as a comment.

According to the documentation of ax.annotate, you should easily specify the line type as dashed, as well as the label placement. A good list of examples can be found here.

You should try something similar to: ax.annotate('dashed line', xy=(0.25,0.2), xytext=(0.6,0.2),arrowprops={'arrowstyle': '-', 'ls': 'dashed'}, va='center', rotate=90)

2 Comments

annotate is such a cumbersome method compared to stem
Sorry for the confusion, I just deleted the '#' in the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.