Suppose I have a set of points x
and a set of corresponding data y
. I now plot these in a scatter plot, plt.scatter(x,y)
. The figure I get contains some x axis tick generated by matplotlib. Is there a way I can attain the automatic ticking, but to add vertical lines from the x-axis to the point in the scatter and label them?
Well, there is a stem
method, much easier to use:
import matplotlib.pyplot as plt
import numpy as np
x, y = np.random.random((2, 20))
fig, ax = plt.subplots()
ax.stem(x, y, markerfmt=' ')
plt.show()
If you want bullets on the top of lines, just remove markerfmt
.
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