Create a Bar Chart with Values in Matplotlib

Recently, I was working on a project where I needed to present sales data for different states in the USA. The challenge was not just to plot a bar chart but also to show the exact values on top of each bar.

If you’ve ever created a bar chart in Python using Matplotlib, you probably noticed that the default chart doesn’t include value labels. This can make it harder for stakeholders to quickly read and understand the numbers.

In this tutorial, I’ll show you how to create a Matplotlib bar chart with values step by step.
I’ll also share multiple methods so you can choose the one that best fits your project.

What is a Bar Chart in Python?

A bar chart is one of the most common types of visualizations. It helps compare categories using rectangular bars, where the length of each bar represents the value.

In Python, Matplotlib makes it very simple to create bar charts. With just a few lines of code, you can build a chart that looks professional and easy to understand.

Example Dataset for the Tutorial

For this tutorial, I’ll use a simple dataset of average monthly household expenses in different US states. This example is practical and relatable for anyone analyzing data in the USA.

Here’s the dataset we’ll use:

states = ["California", "Texas", "New York", "Florida", "Illinois"]
expenses = [4200, 3500, 3900, 3100, 2800]

Now, let’s move on to the methods.

Method 1 – Use plt.bar_label in Python

The first method is the easiest way to add values on top of bars in Python. Matplotlib provides a function called bar_label that makes this task easy.

Here’s the complete code:

import matplotlib.pyplot as plt

# Data
states = ["California", "Texas", "New York", "Florida", "Illinois"]
expenses = [4200, 3500, 3900, 3100, 2800]

# Create figure and axis
fig, ax = plt.subplots(figsize=(8, 5))

# Plot bar chart
bars = ax.bar(states, expenses, color="skyblue")

# Add values on top of bars
ax.bar_label(bars, padding=3)

# Add labels and title
ax.set_xlabel("States")
ax.set_ylabel("Average Monthly Expenses ($)")
ax.set_title("Average Household Expenses in US States")

# Show chart
plt.show()

You can refer to the screenshot below to see the output.

Bar Chart with Values in Matplotlib

When you run this code, you’ll see a clean bar chart with values displayed above each bar.
This is the simplest way to make your Python bar chart more informative.

Method 2 – Add Values Manually Using a Loop

Sometimes, you may want more control over how the values appear. In that case, you can use a loop and the plt.text() function.

Here’s the code:

import matplotlib.pyplot as plt

# Data
states = ["California", "Texas", "New York", "Florida", "Illinois"]
expenses = [4200, 3500, 3900, 3100, 2800]

# Create bar chart
plt.figure(figsize=(8, 5))
bars = plt.bar(states, expenses, color="lightgreen")

# Add values manually
for bar in bars:
    yval = bar.get_height()
    plt.text(bar.get_x() + bar.get_width()/2, yval + 50, 
             f"${yval}", ha="center", va="bottom")

# Add labels and title
plt.xlabel("States")
plt.ylabel("Average Monthly Expenses ($)")
plt.title("Average Household Expenses in US States")

# Show chart
plt.show()

You can refer to the screenshot below to see the output.

Create a Bar Chart with Values in Matplotlib

With this approach, you can format the labels however you like. For example, I added a dollar sign to make the chart more relevant for US household expenses.

Method 3 – Horizontal Bar Chart with Values

In some cases, horizontal bar charts are easier to read, especially when you have long category names. Matplotlib makes it easy to switch from vertical to horizontal bars.

Here’s how you can do it:

import matplotlib.pyplot as plt

# Data
states = ["California", "Texas", "New York", "Florida", "Illinois"]
expenses = [4200, 3500, 3900, 3100, 2800]

# Create horizontal bar chart
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.barh(states, expenses, color="salmon")

# Add values on bars
for bar in bars:
    width = bar.get_width()
    ax.text(width + 50, bar.get_y() + bar.get_height()/2, 
            f"${width}", va="center")

# Add labels and title
ax.set_xlabel("Average Monthly Expenses ($)")
ax.set_ylabel("States")
ax.set_title("Average Household Expenses in US States")

# Show chart
plt.show()

You can refer to the screenshot below to see the output.

Matplotlib Create a Bar Chart with Values

This method is especially useful when working with datasets that have many categories.
It ensures that all labels remain readable without overlapping.

Method 4 – Customize Fonts, Colors, and Styles

In real-world projects, presentation matters as much as accuracy. That’s why I often customize my Python bar charts to match the theme of my reports.

Here’s an example with custom fonts, colors, and gridlines:

import matplotlib.pyplot as plt

# Data
states = ["California", "Texas", "New York", "Florida", "Illinois"]
expenses = [4200, 3500, 3900, 3100, 2800]

# Create bar chart
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(states, expenses, color=["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd"])

# Add values with custom style
ax.bar_label(bars, labels=[f"${x}" for x in expenses], padding=5, fontsize=10, color="black")

# Customize chart
ax.set_xlabel("States", fontsize=12)
ax.set_ylabel("Average Monthly Expenses ($)", fontsize=12)
ax.set_title("Average Household Expenses in US States", fontsize=14, fontweight="bold")
ax.grid(axis="y", linestyle="--", alpha=0.7)

# Show chart
plt.show()

This code produces a more polished chart that looks presentation-ready. It’s perfect for business reports or client presentations in the USA.

When Should You Use a Bar Chart with Values?

From my Python development experience, I’ve found that bar charts with values are best used when:

  • You want to highlight exact numbers in addition to visual comparisons.
  • Your audience prefers quick readability without estimating bar heights.
  • You’re preparing reports or dashboards where clarity is critical.

In this tutorial, I showed you how to create a Matplotlib bar chart with values in Python using different methods. We covered bar_label, manual loops with plt.text(), horizontal bar charts, and customization options.

Both beginners and experienced Python developers can use these techniques to make their charts more professional. The choice of method depends on how much customization you need and the audience you’re presenting to.

You may also read:

Leave a Comment

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.