2

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?

jma
  • 3,580
  • 6
  • 40
  • 60
  • I have no idea if this is possible, but I recommend plotting against the y-axis rather than the x-axis. Otherwise, you will be working against how people typically understand graphs. – Steven Rumbalski Apr 14 '15 at 15:03
  • Think of plotting the density of moss found on the trunk of a tree (as a function of height). Sometimes it is more intuitive to plot against the y axis! – jma Apr 14 '15 at 15:07
  • I'm not sure about doing it directly, but you can easily map the strings to an integer and then change the tick labels. – AMacK Apr 14 '15 at 15:14

1 Answers1

8

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'])
plonser
  • 3,323
  • 2
  • 18
  • 22