#2 Horizontal barplot

 

 

 

 

Here is a tip to turn your barplot horizontal with matplotlib. To do so just call the barh() function instead of bar().

 

 

 

 

 

 

 


# libraries
import numpy as np
import matplotlib.pyplot as plt

# Make fake dataset
height = [3, 12, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')
y_pos = np.arange(len(bars))

# Create horizontal bars
plt.barh(y_pos, height)

# Create names on the y-axis
plt.yticks(y_pos, bars)

# Show graphic
plt.show()

 

Leave a Reply

Your email address will not be published.