Bar charts - vertical

Matplotlib Basics

1 min read

Published Oct 5 2025, updated Aug 17 2026


15
0
0
0

ChartsGraphsMatplotlibNumPyPandasPythonVisualisation

The bar() function creates vertical bars.


Syntax:

plt.bar(x, height, width=0.8, bottom=None, color=None, edgecolor=None, label=None, alpha=1.0)

Parameters:

  • x → x-axis positions or categories
  • height → heights of the bars
  • width → width of each bar (default 0.8)
  • bottom → y-value at which bars start (default 0)
  • color → bar fill colour
  • edgecolor → colour of the bar border
  • label → legend label
  • alpha → transparency (0 to 1)



Basic example

import matplotlib.pyplot as pltx = ['A', 'B', 'C', 'D']y = [5, 7, 3, 8]plt.bar(x, y)plt.title("Basic Vertical Bar Chart")plt.xlabel("Categories")plt.ylabel("Values")plt.show()

matplotlib bar chart vertical basic example




Customise bar colours

import matplotlib.pyplot as pltx = ['A', 'B', 'C', 'D']y = [5, 7, 3, 8]colours = ['red', 'green', 'blue', 'orange']plt.bar(x, y, color=colours)plt.title("Bar Chart with Colours")plt.show()

matplotlib bar chart vertical colours example




Add edge colour and width

import matplotlib.pyplot as pltx = ['A', 'B', 'C', 'D']y = [5, 7, 3, 8]plt.bar(x, y, color='lightgreen', edgecolor='black', linewidth=2)plt.title("Bar Chart with Edges")plt.show()

matplotlib bar chart vertical edge colours example




Bar width and bottom offset

import matplotlib.pyplot as pltx = ['A', 'B', 'C', 'D']y = [5, 7, 3, 8]plt.bar(x, y, width=0.2, bottom=2, color='red')plt.title("Bar Chart with Width and Bottom Offset")plt.show()

matplotlib bar chart vertical width bottom example




Add labels on top of the bars

import matplotlib.pyplot as pltx = ['A', 'B', 'C', 'D']y = [5, 7, 3, 8]bars = plt.bar(x, y, color='lightgreen')plt.title("Bar Chart with Labels")for bar in bars:    plt.text(bar.get_x() + bar.get_width()/2, bar.get_height(),             str(bar.get_height()), ha='center', va='bottom')plt.show()

matplotlib bar chart vertical bar labels example




Grouped bar chart

import matplotlib.pyplot as pltimport numpy as npx = np.arange(4)y1 = [5, 7, 3, 8]y2 = [6, 4, 7, 5]plt.bar(x - 0.2, y1, width=0.4, label='2024')plt.bar(x + 0.2, y2, width=0.4, label='2025')plt.xticks(x, ['A','B','C','D'])plt.legend()plt.title("Grouped Vertical Bar Chart")plt.show()

matplotlib bar chart vertical grouped example




Stacked bar chart

import matplotlib.pyplot as pltimport numpy as npx = np.arange(4)  # positionsy1 = [5, 7, 3, 8]y2 = [6, 4, 7, 5]plt.bar(x, y1, label='2024', color='skyblue')plt.bar(x, y2, bottom=y1, label='2025', color='orange')plt.xticks(x, ['A','B','C','D'])plt.legend()plt.title("Stacked Vertical Bar Chart")plt.show()

matplotlib bar chart vertical stacked example
© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Matplotlib Basics | Bar charts - vertical | SimpleSteps.guide