I have the following list:
[('und', 52),
('die', 36),
('von', 33),
('der', 29),
('in', 20),
('das', 17),
('für', 17),
('eine', 15),
('des', 14),
('Die', 14),
('ODP', 14),
('wurde', 13),
('zu', 13)]
With the following code I convert it to a pandas dataframe:
df = pd.DataFrame(sorted_by_value, columns=['Wort', 'Vorkommen'])
Then I plot it:
fig, ax_lst = plt.subplots(1,1) # a figure with a 2x2 grid of Axes
df10 = df[:20]
df10.Vorkommen.plot(kind='barh')
plt.show()
How can I change the y axis from the index to the words?
By default plot.barh
uses the index. You can explicitly set the x and y values like so:
df.plot.barh(x='Wort', y='Vorkommen')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With