Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical lines to points in scatter plot

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?

like image 705
Joshhh Avatar asked Nov 30 '16 17:11

Joshhh


1 Answers

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.

like image 113
xamgore Avatar answered Sep 19 '22 14:09

xamgore