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 Change the Font Size of Colorbars in Matplotlib
Next article icon

Change Font Size in Matplotlib

Last Updated : 03 Feb, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Matplotlib library is mainly used to create 2-dimensional graphs and plots. It has a module named Pyplot which makes things easy for plotting. To change the font size in Matplotlib, the two methods given below can be used with appropriate parameters: 

Change Font Size using fontsize

You can set the font size argument, figsize change how Matplotlib treats fonts in general, or even change the figure size.

Python3

import matplotlib.pyplot as plt
 
# setting font sizeto 30
fig, plt = plt.subplots(figsize=(10, 6))
 
x = [1, 2, 3, 4, 5, 6]
y = [0, 2, 4, 6, 8, 10]
 
# plotting a plot
plt.plot(x, y)
 
plt.set_title('Title', fontsize=20)
plt.set_xlabel('Time', fontsize=16)
plt.set_ylabel('Intensity', fontsize=16)
                      
                       

Output:

Change Font Size in Matplotlib

 

Change Font Size in Matplotlib rcParams.update()

The rcParams is an instance of the Matplotlib library for handling default Matplotlib values hence to change the default font size we just have to pass the value to the key font.size.

Python3

import matplotlib.pyplot as plt
 
# setting font sizeto 30
plt.rcParams.update({'font.size': 30})
 
x = [1, 2, 3, 4, 5, 6]
y = [0, 2, 4, 6, 8, 10]
 
# plotting a plot
plt.plot(x, y)
 
# setting title name
plt.title("Title")
 
# setting x axis label
plt.xlabel("x axis")
 
# setting y axis label
plt.ylabel("y axis")
 
plt.show()
                      
                       

Output:

Change Font Size in Matplotlib

 

Change Font Size in Matplotlib rc(group, **kwargs)

This function sets the current rc params. The group is the grouping for the rc like line, font, axes, etc and kwargs is a dictionary attribute name and value pairs.

Python3

import matplotlib.pyplot as plt
 
 
# creating a dictionary
font = {'size': 10}
 
# using rc function
plt.rc('font', **font)
 
x = [1, 2, 3, 4, 5, 6]
y = [0, 2, 4, 6, 8, 10]
 
# plotting a plot
plt.plot(x, y)
 
# setting title name
plt.title("Title")
 
# setting x axis label
plt.xlabel("x axis")
 
# setting y axis label
plt.ylabel("y axis")
 
plt.show()
                      
                       

Output:

Change Font Size in Matplotlib

 



Next Article
How to Change the Font Size of Colorbars in Matplotlib

P

patildhanu4111999
Improve
Article Tags :
  • Python
  • Technical Scripter
  • Python-matplotlib
  • Technical Scripter 2020
Practice Tags :
  • python

Similar Reads

  • How to Change Fonts in matplotlib?
    Prerequisites:  Matplotlib  In this article, we will see how can we can change the font family of our graph using matplotlib. A variety of fonts are in fact supported by matplotlib, alone has to do in order to implement is pass the name as value to fontname parameter. Approach: Import required libra
    2 min read
  • Matplotlib - Change Slider Color
    In this article, we will see how to change the slider color of a plot in Matplotlib. First of all, let's learn what is a slider widget. The Slider widget in matplotlib is used to create a scrolling slider, and we can use the value of the scrolled slider to make changes in our python program. By defa
    3 min read
  • Change plot size in Matplotlib - Python
    Plots are an effective way of visually representing data and summarizing it beautifully. However, if not plotted efficiently it seems appears complicated. Python's Matplotlib provides several libraries for data representation. While making a plot we need to optimize its size. In this article, we wil
    3 min read
  • 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 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 Change Line Color in Matplotlib?
    Matlab's plotting functions are included in Python by the Inclusion of the library Matplotlib. The library allows the plotting of the data of various dimensions without ambiguity in a plot. The library is widely used in Data Science and Data visualization. In this article, we will discuss how to cha
    3 min read
  • Change the legend position in Matplotlib
    In this article, we will learn how to Change the legend position in Matplotlib. Let's discuss some concepts : Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a multi-platform data visualization library built on NumPy arrays and designed to figure
    2 min read
  • Change the error bar thickness in Matplotlib
    Matplotlib is a Python library which is widely used by data analytics. Matplotlib.pyplot.errorbar()  is a pyplot module consisting of a function which provides a MATLAB like interface. Changing Error Bar Thickness Before changing the thickness of error bar let us see what error bar is and how we can
    2 min read
  • How to change the size of axis labels in Matplotlib?
    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 plo
    2 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
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