Add Text to the Bottom and Right of a Matplotlib Plot

While working on a Python data visualization project, I needed to add custom text to the bottom and right sides of a Matplotlib plot. It seemed like a simple task, but I quickly realized that positioning text precisely in Matplotlib requires understanding how coordinates and alignment work.

In this tutorial, I’ll share two simple and effective ways to add text to both the bottom and right of a Matplotlib plot. I’ll walk you through each method step-by-step, using practical examples that you can easily apply to your own Python projects.

Whether you’re labeling plots for a report, adding credits, or annotating your visualizations for better storytelling, these techniques will help you make your Python plots look professional and well-structured.

Add Text to the Bottom of a Matplotlib Plot in Python

When you want to add a caption, label, or note below your Python plot, there are two main approaches you can use. I’ll show you both.

Method 1 – Use Matplotlib’s plt.text() to Add Text at the Bottom

The simplest way to add text to the bottom of a Matplotlib plot is by using the plt.text() function. This method allows you to specify the x and y coordinates where the text should appear.

Here’s how I usually do it in my Python projects.

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 12, 8, 15, 10]

plt.plot(x, y, marker='o', color='steelblue')

# Add text at the bottom
plt.text(3, min(y) - 1, 'Sales data for Q1 - USA Region', 
         ha='center', va='top', fontsize=12, color='darkred')

plt.title('Quarterly Sales Report')
plt.xlabel('Weeks')
plt.ylabel('Sales Volume')

plt.show()

I executed the above example code and added the screenshot below.

Add Text to the Bottom and Right of a Matplotlib Plot

In this example, I used plt.text() with the following parameters:

  • The first two arguments (3, min(y) – 1) define the position of the text.
  • The ha (horizontal alignment) and va (vertical alignment) parameters ensure the text is centered and placed neatly below the plot.

This method is great when you’re working with data coordinates and want the text position to relate to your data range.

Method 2 – Use ax.text() with Axes Coordinates in Matplotlib

If you want the text to stay fixed at the bottom of the figure, regardless of the data range, use axes coordinates instead of data coordinates. This gives you more control over the placement.

Here’s how I do it:

import matplotlib.pyplot as plt

# Create figure and axes
fig, ax = plt.subplots()

# Sample data
x = [1, 2, 3, 4, 5]
y = [50, 70, 60, 90, 80]

ax.plot(x, y, color='teal', marker='s')

# Add text using axes coordinates
ax.text(0.5, -0.1, 'Data Source: U.S. Sales Department', 
        transform=ax.transAxes, ha='center', va='top', fontsize=11, color='purple')

ax.set_title('Monthly Sales Data - Python Example')
ax.set_xlabel('Month')
ax.set_ylabel('Revenue ($)')

plt.tight_layout()
plt.show()

I executed the above example code and added the screenshot below.

Add Text to the Bottom and Right of Matplotlib Plot

Here, I used transform=ax.transAxes, which tells Matplotlib to place the text relative to the axes instead of the data.

  • (0.5, -0.1) means the text is horizontally centered (0.5) and slightly below the bottom edge (-0.1).
  • This is ideal for adding captions or notes that should not move when the data range changes.

Add Text to the Right of a Matplotlib Plot in Python

Sometimes, you may want to add a note, label, or even a small annotation on the right side of your plot. This could be useful for indicating additional information, such as data sources, version numbers, or context for the visualization.

Let’s look at two easy ways to do this in Python.

Method 1 – Use plt.text() with Data Coordinates

Just like before, we can use plt.text() to place text on the right side of the plot. The trick is to select x and y coordinates that position the text just outside the plot area.

Here’s a simple Python example:

import matplotlib.pyplot as plt

# Sample data
x = [10, 20, 30, 40, 50]
y = [100, 120, 90, 160, 130]

plt.plot(x, y, marker='o', color='darkorange')

# Add text to the right side
plt.text(max(x) + 2, y[-1], 'Target Achieved →', 
         ha='left', va='center', fontsize=12, color='darkgreen')

plt.title('Performance Metrics - Python Visualization')
plt.xlabel('Units Sold')
plt.ylabel('Profit ($)')

plt.show()

I executed the above example code and added the screenshot below.

Add Text to Bottom of a Matplotlib Plot

In this code:

  • I placed the text slightly beyond the maximum x-value (max(x) + 2) so that it appears to the right of the plot.
  • The ha=’left’ ensures the text aligns neatly with the right edge.

This approach works well when you want the text to relate directly to specific data points.

Method 2 – Use ax.text() in Axes Coordinates in Matplotlib

If you prefer the text to be fixed at the right edge of the plot, regardless of the data range, then using axes coordinates is a better choice. This is especially useful when creating dashboards or consistent layouts in Python.

Here’s how I add fixed right-side text using ax.text():

import matplotlib.pyplot as plt

# Create figure and axes
fig, ax = plt.subplots()

# Sample data
x = [1, 2, 3, 4, 5]
y = [5, 7, 6, 8, 7]

ax.plot(x, y, color='navy', marker='^')

# Add text at the right using axes coordinates
ax.text(1.05, 0.5, 'Python Data Visualization', 
        transform=ax.transAxes, rotation=90, ha='left', va='center', fontsize=12, color='crimson')

ax.set_title('Weekly Growth Report')
ax.set_xlabel('Week')
ax.set_ylabel('Growth (%)')

plt.tight_layout()
plt.show()

I executed the above example code and added the screenshot below.

Add Text to the Right of Matplotlib Plot

In this example:

  • (1.05, 0.5) places the text slightly outside the right boundary of the axes.
  • The rotation=90 parameter rotates the text vertically, making it easy to read along the right edge.
  • Because we used transform=ax.transAxes, the text position remains consistent even if the data range changes.

This method is perfect when you want to add a consistent label, note, or annotation to the side of multiple Python plots.

Bonus Tip – Formatting and Styling Text in Matplotlib

Once you’ve mastered positioning text, you can easily enhance your visualization by styling it. Matplotlib allows you to customize font size, color, weight, rotation, and alignment.

Here’s a quick example that combines both bottom and right text in one Python plot:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

x = [1, 2, 3, 4, 5]
y = [15, 25, 20, 30, 25]

ax.plot(x, y, color='royalblue', linewidth=2, marker='o')

# Add bottom text
ax.text(0.5, -0.15, 'Report generated using Python & Matplotlib', 
        transform=ax.transAxes, ha='center', va='top', fontsize=11, color='gray')

# Add right text
ax.text(1.05, 0.5, 'Confidential', 
        transform=ax.transAxes, rotation=90, ha='left', va='center', fontsize=12, color='red', fontweight='bold')

ax.set_title('Annual Revenue Analysis')
ax.set_xlabel('Quarter')
ax.set_ylabel('Revenue ($ Millions)')

plt.tight_layout()
plt.show()

This approach gives your Python plot a professional touch, perfect for presentations, reports, or dashboards.

So that’s how you can easily add text to the bottom and right of a Matplotlib plot in Python.

To summarize:

  • Use plt.text() when you want to position text based on data coordinates.
  • Use ax.text() with transform=ax.transAxes when you want the text to stay fixed relative to the plot area.
  • Combine these techniques to add captions, data sources, or annotations anywhere around your Python plots.

I’ve used these methods countless times in my projects, especially when preparing visual reports for U.S.-based clients where clear labeling and professional formatting matter. Once you get comfortable with these techniques, you’ll find it easy to customize your plots exactly the way you want.

You can also read other Matplotlib tutorials:

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.