In this tutorial, we will look at how to bold the text appearing in different parts of a matplotlib plot with the help of some examples.
To bold text in a matplotlib plot, you can use the keyword argument fontweight
and pass 'bold'
as its value when adding different texts to a plot. For example, to bold the title of a matplotlib plot, use the fontweight
argument when assigning the title using matplotlib.pyplot.title()
function.
# bold the title plt.title("My plot title", fontweight='bold')
Let’s now look at some examples of using bolding text in a matplotlib plot.
First, let’s create a line plot with some text as the plot title and the axes titles with the default font settings.
import matplotlib.pyplot as plt # x values - years x = [2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020] # y values - curde oil price per barrel in USD y = [94.88, 94.05, 97.98, 93.17, 48.66, 43.29, 50.80, 65.23, 56.99, 39.68] # plot x and y on a line plot plt.plot(x, y) # add axes labels plt.xlabel('Year') plt.ylabel('Crude oil price USD/barrel') # add plot title plt.title("Crude oil prices in 2010s")
Output:

Example 1 – Bold the plot title in matplotlib
Let’s now plot the above line chart again but this time with the plot title bolded.
# plot x and y on a line plot plt.plot(x, y) # add axes labels plt.xlabel('Year') plt.ylabel('Crude oil price USD/barrel') # add plot title plt.title("Crude oil prices in 2010s", fontweight='bold')
Output:

You can see that the plot title is now in bold text.
Introductory ⭐
- Harvard University Data Science: Learn R Basics for Data Science
- Standford University Data Science: Introduction to Machine Learning
- UC Davis Data Science: Learn SQL Basics for Data Science
- IBM Data Science: Professional Certificate in Data Science
- IBM Data Analysis: Professional Certificate in Data Analytics
- Google Data Analysis: Professional Certificate in Data Analytics
- IBM Data Science: Professional Certificate in Python Data Science
- IBM Data Engineering Fundamentals: Python Basics for Data Science
Intermediate ⭐⭐⭐
- Harvard University Learning Python for Data Science: Introduction to Data Science with Python
- Harvard University Computer Science Courses: Using Python for Research
- IBM Python Data Science: Visualizing Data with Python
- DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization
Advanced ⭐⭐⭐⭐⭐
- UC San Diego Data Science: Python for Data Science
- UC San Diego Data Science: Probability and Statistics in Data Science using Python
- Google Data Analysis: Professional Certificate in Advanced Data Analytics
- MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning
- MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science
🔎 Find Data Science Programs 👨💻 111,889 already enrolled
Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.
Example 2 – Bold the axes labels in matplotlib
We can similarly make the axes labels bold by using the fontweight
keyword argument when setting the respective axes labels.
Let’s make both the x-axis and the y-axis labels bold.
# plot x and y on a line plot plt.plot(x, y) # add axes labels plt.xlabel('Year', fontweight='bold') plt.ylabel('Crude oil price USD/barrel', fontweight='bold') # add plot title plt.title("Crude oil prices in 2010s")
Output:

Now, the axes titles are bold.
You can similarly format the text with other keyword arguments such as fontsize
, horizontalalignment
, etc.
Let’s make the title of the original line plot bold and also increase its font size.
# plot x and y on a line plot plt.plot(x, y) # add axes labels plt.xlabel('Year') plt.ylabel('Crude oil price USD/barrel') # add plot title plt.title("Crude oil prices in 2010s", fontweight='bold', fontsize=18)
Output:

You might also be interested in –
- Matplotlib – Remove the frame without altering the ticks and the tick labels
- Add Title to Each Subplot in Matplotlib
- Matplolib – Hide Axis in a Plot (Code with Examples)
- Matplotlib – Change the Number of Ticks in a Plot
- Remove Tick Labels from a Plot in Matplotlib
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.