Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a pin plot in matplotlib

How do you create a 'pin plot' in matplotlib, or is another library required? The code I have to plot points is below. The top plot is the output of my code, the second is the ideal output.

def getData(n):
    data = []
    for i in range(n):
        data.append(i)
    return data

fig, axs = plt.subplots(2, 2)
n = 10
axs[0, 0].scatter([i for i in range(n)], getData(n))
plt.show()

Output

Pin Plot

like image 816
Alice F Avatar asked May 02 '26 09:05

Alice F


1 Answers

This is called a stem plot in matplotlib:

plt.stem(range(10), markerfmt='None', basefmt='C0-')

enter image description here

like image 98
Stef Avatar answered May 03 '26 23:05

Stef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!