Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib line plot of x values against y

I have a list of values x that I want to plot (with lines) against the y axis.

That is, if x = [3, 5, 2, 4] and y = ['A', 'B', 'C', 'D'], the plot might look like this (except not hand-drawn):

the plot style I mean

And I'm afraid I don't see anything in the matplotlib.pyplot docs / SO / google pointing me in the right direction, even what to call it. Any pointers?

like image 365
jma Avatar asked Dec 09 '25 06:12

jma


1 Answers

I think you look for something like this

import numpy as np
import matplotlib.pyplot as plt

fig,ax = plt.subplots(1)

# create some x data and some integers for the y axis
x = np.array([3,5,2,4])
y = np.arange(4)

# plot the data
ax.plot(x,y)

# tell matplotlib which yticks to plot 
ax.set_yticks([0,1,2,3])

# labelling the yticks according to your list
ax.set_yticklabels(['A','B','C','D'])
like image 158
plonser Avatar answered Dec 11 '25 11:12

plonser



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!