Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Pandas
  • Numpy
  • Seaborn
  • Ploty
  • Data visualization
  • Data Analysis
  • Power BI
  • Tableau
  • Machine Learning
  • Deep Learning
  • NLP
  • Computer Vision
  • Data Science for Beginners
  • Data Science interview questions
  • Data analysis interview questions
  • NLP Interview questions
Open In App
Next Article:
How to Set Tick Labels Font Size in Matplotlib?
Next article icon

How to change the size of axis labels in Matplotlib?

Last Updated : 15 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Matplotlib is a Python library that helps in visualizing and customizing various plots. One of the customization you can do is to change the size of the axis labels to make reading easier. In this guide, we’ll look how to adjust font size of axis labels using Matplotlib.

Let’s start with a basic plot to see how it works

Python
import matplotlib.pyplot as plt  x = [1, 2, 3, 4, 5] y = [9, 8, 7, 6, 5]  fig, ax = plt.subplots() ax.plot(x, y)  ax.set_xlabel('x-axis') ax.set_ylabel('y-axis')  plt.show() 

Output 

download6
Sample Plot

1. Using xlabel() and ylabel()

We can change the size of axis labels by using the fontsize parameter in the xlabel() and ylabel() functions. These method allow you to specify the font size directly when setting the labels.

Python
import matplotlib.pyplot as plt  x = [1, 2, 3, 4, 5] y = [9, 8, 7, 6, 5]  fig, ax = plt.subplots() ax.plot(x, y) ax.plot(x, y)  ax.set_xlabel('x-axis', fontsize = 25) ax.set_ylabel('y-axis', fontsize = 20)  plt.show() 

Output:

Screenshot-2024-12-12-121427
Resulting plot after adjusting axis label size in Matplotlib

Here we defined x-axis font as 25 and y-axis font to be 20.

2. Using set_xlabel() and set_ylabel()

After plotting you can use set_xlabel() and set_ylabel() methods of the Axes object. These methods are used to modify labels after your plot has already been created.

Python
import matplotlib.pyplot as plt  x = [1, 2, 3, 4, 5] y = [10, 20, 25, 30, 40]  plt.plot(x, y)  plt.gca().set_xlabel('Custom X-Axis Label', fontsize=20) plt.gca().set_ylabel('Custom Y-Axis Label', fontsize=20)  plt.show() 

Output:

Screenshot-2024-12-12-123717
Resulting output after adjusting axis label size in Matplotlib

3. Changing Font Size Globally with rcParams

If you require consistent font sizes across multiple plots adjusting the default settings with rcParams is a better approach. This method sets a global font size for all axis labels in your environment.

Python
import matplotlib as mpl import matplotlib.pyplot as plt  mpl.rcParams['axes.labelsize'] = 20  x = [5, 10, 4, 2, 8] y = [49, 50, 90, 43, 87]  plt.plot(x, y)  plt.xlabel('Custom X-Axis Label') plt.ylabel('Custom Y-Axis Label')  plt.show() 

Output:

Screenshot-2024-12-12-124140
Resulting output after adjusting axis label size in Matplotlib

Adjusting size of axis labels improves readability and understanding. Whether it's about sharing your plots with someone or just understanding the data alone proper label size makes your visuals better. Using the given ways you will can get neat, professional and clear charts.


Next Article
How to Set Tick Labels Font Size in Matplotlib?
author
ayushmankumar7
Improve
Article Tags :
  • Python
  • AI-ML-DS
  • Python-matplotlib
Practice Tags :
  • python

Similar Reads

  • How to Change the Size of Figures in Matplotlib?
    Matplotlib provides a default figure size of 6.4 inches in width and 4.8 inches in height. While this is suitable for basic graphs, various situations may require resizing figures for better visualization, presentation or publication. This article explores multiple methods to adjust the figure size
    3 min read
  • How to Hide Axis Text Ticks or Tick Labels in Matplotlib?
    Matplotlib library in python shows axis ticks and tick labels by default. Sometimes it is important to hide these axis ticks and tick labels. In this article we will discuss some methods by which this can be done. Before that lets have a understanding about each of them: Ticks: Axes' points are mark
    3 min read
  • How to change size of labels in the Bokeh legend?
    In this article, we will be learning about how to change the size of labels in bokeh legend. Legend plays a very important role in bokeh. With the help of legend, we can point to various types of glyphs in a plot that bokeh provides us, and can customize them according to our choice. Along with that
    5 min read
  • How to Set Tick Labels Font Size in Matplotlib?
    Prerequisite: Matplotlib Matplotlib is one of the most widely used data visualization libraries in Python. It provides a variety of ways to create high-quality 2D plots. One important aspect of making plots readable and aesthetically pleasing is formatting tick labels, including adjusting their font
    3 min read
  • How To Adjust Position of Axis Labels in Matplotlib?
    Matplotlib is a powerful Python library for creating graphs and charts. By default, it places axis labels in standard positions, but sometimes you might want to move them for better readability or design. This article explains easy ways to adjust the position of axis labels in Matplotlib to make you
    3 min read
  • How to change axes limits in matplotlib?
    Sometimes, when you create a plot default axes X and Y may not show the full picture you want. Changing the axes limits helps you focus on specific data ranges or improve how your plot looks. There are two methods available in Axes module tochange the limits: matplotlib.axes.Axes.set_xlim(): It is u
    2 min read
  • How to Change the Font Size of Colorbars in Matplotlib
    Matplotlib is a powerful and widely used library in Python for data visualization. It offers a variety of plotting functions to create complex graphs and charts. One common visualization is a heatmap, which often includes a color bar to indicate the scale of values represented by colors. Adjusting t
    4 min read
  • How to Rotate X-Axis Tick Label Text in Matplotlib?
    Matplotlib is an amazing and one of the most widely used data visualization libraries in Python for plots of arrays. It is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It is much popular because of its customization options as w
    3 min read
  • How to change the font size of the Title in a Matplotlib figure ?
    In this article, we are going to discuss how to change the font size of the title in a figure using matplotlib module in Python. As we use matplotlib.pyplot.title() method to assign a title to a plot, so in order to change the font size, we are going to use the font size argument of the pyplot.title
    2 min read
  • How to set font size of Matplotlib axis Legend?
    Prerequisite: Matplotlib In this article, we will see how to set the font size of matplotlib axis legend using Python. For this, we will use rcParams() methods to increase/decrease the font size. To use this we have to override the matplotlib.rcParams['legend.fontsize'] method. Syntax: matplotlib.rc
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences