Matplotlib > Horizontal bar plot (customized)

Name
Code
Output
# Data
x = [1,2,3,4]
y = [1,2,1,5]
# New Figure
fig = matplotlib.pyplot.figure(figsize=(7,4),facecolor='silver')
# New Axes
ax = fig.add_subplot(111,facecolor='azure')
# Add grid
ax.grid(color='b', linestyle='-', linewidth=0.5)
# set ticks
ax.xaxis.set_ticks(numpy.arange(min(x), max(x)+1, 1.0))
# Plot the data
ax.barh(x, y,color=['red','lime','green','orange'],tick_label=['A','B','C','D'])
ax.set(title="Plot title", xlabel="x axis", ylabel="y axis")
# Fit the plot layout
matplotlib.pyplot.tight_layout()
# Show the plot
matplotlib.pyplot.show()

       
           Horizontal bar plot (customized)