Matplotlib plot without linear ordered

Viewed 41

Is it possible to draw matplotlib chart without using a pandas plot to draw a chart without linear ordering the values on the left?

df = pd.DataFrame({
'x':[3,0,5],
'y':[10,4,20]
})

Chart made with the help of DataFrame:

plt.barh(df['x'],df['y'])

Without dataframe:

x = [3,0,5]
y= [10,4,20]
plt.barh(x,y)

it gives me the same result

Matplotlib chart Output chart: enter image description here

df.plot.barh('x','y')

Pandas output chart: enter image description here

I would like to get such an output only with normal numbers and not numbers as the type of str

plt.barh(['3','0','5'],[10,4,20])

enter image description here Is it possible? How could i get it?

1 Answers

You can use the index of the dataframe as y parameter and use the x values of the dataframe as tick_label:

plt.barh(df.index, width=df['y'], tick_label=df['x'])

enter image description here

Related