Add Text to Bar and Scatter Plots in Matplotlib

I first started working with Matplotlib in Python, and I often created bar and scatter plots to visualize data. However, I quickly realized that adding text annotations made my charts much more meaningful. Whether you’re labeling bars with values or marking specific points in a scatter plot, text helps your audience understand your insights instantly.

In this tutorial, I’ll show you how to add text to bar and scatter plots in Matplotlib using Python. I’ll share two simple and practical methods for each plot type that I personally use in my data visualization projects.

All examples here use real-world data inspired by common U.S. business and marketing scenarios. You can easily adapt these examples for your own Python projects.

Add Text to Bar Plots in Matplotlib

Bar charts are one of the most common types of plots in Python. They’re great for comparing categories, such as sales by region or revenue by product. Adding text labels can make these charts more informative and professional.

Let’s go through two easy methods to add text to bar plots in Matplotlib.

Method 1 – Add Text to Bar Plot Using ax.bar_label()

When I discovered the bar_label() function in Matplotlib, it instantly became my go-to method. It’s efficient, clean, and built specifically for labeling bars.

Here’s how you can use it in Python.

import matplotlib.pyplot as plt

# Sample data: Monthly sales revenue across U.S. regions
regions = ['East', 'West', 'North', 'South']
sales = [52000, 48000, 61000, 57000]

# Create a bar chart
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(regions, sales, color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728'])

# Add labels to each bar using bar_label()
ax.bar_label(bars, labels=[f'${val:,}' for val in sales], padding=3, color='black', fontsize=11)

# Add titles and labels
ax.set_title('Monthly Sales Revenue by Region (USD)', fontsize=14, fontweight='bold')
ax.set_xlabel('Region')
ax.set_ylabel('Sales Revenue')

plt.tight_layout()
plt.show()

You can see the output in the screenshot below.

How to Add Text to Bar Plots in Matplotlib

This method automatically places labels on top of the bars, saving you time and effort. I often use it when preparing quick visual reports for clients because it’s clean and requires minimal customization.

If you want to adjust the label position, you can tweak the padding parameter or use the label_type argument (e.g., ‘center’ or ‘edge’).

Method 2 – Add Text to Bar Plot Using ax.text()

Before bar_label() existed, I used the ax.text() method to manually place text on bars. It gives you full control over the position and style of each label.

Here’s how you can do it in Python.

import matplotlib.pyplot as plt

# Sample data: Average customer satisfaction scores
categories = ['Product Quality', 'Delivery', 'Support', 'Pricing']
scores = [8.5, 7.8, 9.1, 8.0]

fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(categories, scores, color='#17becf')

# Add text labels manually
for bar in bars:
    height = bar.get_height()
    ax.text(bar.get_x() + bar.get_width()/2, height + 0.1, f'{height:.1f}', 
            ha='center', va='bottom', fontsize=11, color='black')

# Add titles and labels
ax.set_title('Customer Satisfaction Scores by Category', fontsize=14, fontweight='bold')
ax.set_xlabel('Category')
ax.set_ylabel('Average Score')

plt.tight_layout()
plt.show()

You can see the output in the screenshot below.

Add Text to Bar Plots in Matplotlib

This approach is perfect when you need precise control over the label position. I often use it when I want to align text differently or add custom formatting to each label.

Add Text to Scatter Plots in Matplotlib

Scatter plots are excellent for showing relationships between variables. For example, you might want to visualize the relationship between advertising spend and sales revenue. Adding text helps identify specific data points, such as outliers or key performers.

Let’s go through two practical methods to add text to scatter plots in Matplotlib using Python.

Method 1 – Add Text to Scatter Plot Using ax.text()

This is the most straightforward method to annotate points in a scatter plot. You can loop through your data and use ax.text() to add text labels.

Here’s an example in Python.

import matplotlib.pyplot as plt

# Sample data: Advertising spend vs. sales revenue (in USD)
advertising_spend = [10, 15, 20, 25, 30, 35, 40]
sales_revenue = [25, 32, 40, 43, 50, 53, 60]
regions = ['NY', 'CA', 'TX', 'FL', 'IL', 'WA', 'OH']

fig, ax = plt.subplots(figsize=(8, 5))
ax.scatter(advertising_spend, sales_revenue, color='#ff7f0e', s=100)

# Add text labels for each point
for i, region in enumerate(regions):
    ax.text(advertising_spend[i]+0.5, sales_revenue[i], region, fontsize=10, color='black')

# Add titles and labels
ax.set_title('Advertising Spend vs. Sales Revenue', fontsize=14, fontweight='bold')
ax.set_xlabel('Advertising Spend (in $1000s)')
ax.set_ylabel('Sales Revenue (in $1000s)')

plt.tight_layout()
plt.show()

You can see the output in the screenshot below.

How to Add Text to Scatter Plots in Matplotlib

This method is simple and flexible. I use it frequently when I need to label specific points or highlight regions on scatter plots. You can adjust the label position by modifying the x and y offsets in ax.text().

Method 2 – Add Text to Scatter Plot Using ax.annotate()

If you want more control over how your labels connect to points, ax.annotate() is the best choice. It allows you to add arrows, control alignment, and style your annotations.

Here’s how you can use it in Python.

import matplotlib.pyplot as plt

# Sample data: Average income vs. education level across U.S. cities
education_years = [12, 13, 14, 15, 16, 17, 18]
average_income = [40000, 42000, 45000, 48000, 52000, 55000, 60000]
cities = ['Austin', 'Denver', 'Chicago', 'Boston', 'Seattle', 'San Diego', 'New York']

fig, ax = plt.subplots(figsize=(9, 6))
ax.scatter(education_years, average_income, color='#2ca02c', s=100)

# Add annotations for each city
for i, city in enumerate(cities):
    ax.annotate(city,
                (education_years[i], average_income[i]),
                textcoords="offset points",
                xytext=(5, 5),
                ha='left',
                fontsize=10,
                color='black')

# Add titles and labels
ax.set_title('Average Income vs. Education Level in U.S. Cities', fontsize=14, fontweight='bold')
ax.set_xlabel('Average Years of Education')
ax.set_ylabel('Average Annual Income (USD)')

plt.tight_layout()
plt.show()

You can see the output in the screenshot below.

Add Text to Scatter Plots in Matplotlib

I often use ax.annotate() when preparing presentations or dashboards that require professional, readable charts. It’s especially useful when you need to connect text to specific data points with arrows or offsets.

Tips for Adding Text to Plots in Matplotlib

After years of working with Python and Matplotlib, here are a few tips I’ve found helpful when adding text to bar and scatter plots:

  1. Use consistent font sizes – Keep labels readable but not overwhelming.
  2. Avoid overlapping text – Adjust positions or use adjust_text from the adjustText library if needed.
  3. Add context – Labels should add meaning, not clutter.
  4. Use color wisely – Choose contrasting colors for better visibility.
  5. Keep it simple – Less is often more when it comes to annotations.

Key Takeaways

  • ax.bar_label() is the easiest way to label bars in Python’s Matplotlib.
  • ax.text() gives you full manual control for both bar and scatter plots.
  • ax.annotate() is ideal for detailed annotations with arrows or offsets.
  • Proper text placement improves readability and storytelling in your visualizations.

Adding text to bar and scatter plots in Matplotlib using Python might seem like a small detail, but it dramatically improves how your audience interprets your data. Whether you’re preparing a business report, a marketing dashboard, or a data science presentation, well-placed labels make your visualizations look professional and insightful.

I hope you found this tutorial helpful. Try these methods in your next Python project and see how much more engaging your charts become.

You can also read the other tutorials related to Matplotlib:

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.