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 Line Color in Matplotlib?
Next article icon

How to Change Point to Comma in Matplotlib Graphics in Python

Last Updated : 21 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

We are given a Matplotlib Graph and our task is to change the point to a comma in Matplotlib Graphics such that there is only a comma in the whole graph instead of a point. In this article, we will see how we can change the point to comma in Matplotlib Graphics in Python.

Change Point to Comma in Matplotlib Graphics in Python

Below are some of the ways by which we can change the point to a comma in Matplotlib graphics in Python:

  1. Using String Replace in Tick Labels
  2. Using Custom Tick Formatter

Using String Replace in Tick Labels

In this example, a simple line plot is created using Matplotlib, representing data points with purple lines. The x and y-axis tick labels are customized to replace decimal points with commas for improved readability.

Python3
import matplotlib.pyplot as plt  # Example data x = [1, 2, 3, 4, 5] y = [2.5, 1.5, 3.5, 2.0, 4.5]  # Plot plt.plot(x, y, 'purple') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Example Plot') plt.grid(True)  # Replace points with commas in tick labels plt.xticks([tick for tick in plt.xticks()[0]], [            str(tick).replace('.', ',') for tick in plt.xticks()[0]]) plt.yticks([tick for tick in plt.yticks()[0]], [            str(tick).replace('.', ',') for tick in plt.yticks()[0]])  plt.show() 

Output:

Screenshot-2024-03-08-215624
Use String Replace

Using Custom Tick Formatter

In this example, a line plot is generated using Matplotlib with gold-colored lines. The x and y-axis tick labels are formatted to replace decimal points with commas for enhanced visual presentation, achieved by defining a custom formatting function using FuncFormatter.

Python3
import matplotlib.pyplot as plt from matplotlib.ticker import FuncFormatter  # Example data x = [1, 2, 3, 4, 5] y = [2.5, 1.5, 3.5, 2.0, 4.5]  # Plot plt.plot(x, y, 'gold') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Example Plot') plt.grid(True)   def comma_formatter(x, pos):     return str(x).replace('.', ',')   plt.gca().xaxis.set_major_formatter(FuncFormatter(comma_formatter)) plt.gca().yaxis.set_major_formatter(FuncFormatter(comma_formatter))  plt.show() 

Output:

a
By Custom Tick Formatter

Next Article
How to Change Line Color in Matplotlib?
author
hadaa914
Improve
Article Tags :
  • Python
  • Python-matplotlib
  • Matplotlib Pyplot-class
Practice Tags :
  • python

Similar Reads

  • How to Change the Line Width of a Graph Plot in Matplotlib with Python?
    Prerequisite : Matplotlib  In this article we will learn how to Change the Line Width of a Graph Plot in Matplotlib with Python. For that one must be familiar with the given concepts: Matplotlib : Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a
    2 min read
  • How to Add Markers to a Graph Plot in Matplotlib with Python?
    In this article, we will learn how to add markers to a Graph Plot in Matplotlib with Python. For that just see some concepts that we will use in our work. Graph Plot: A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variable
    2 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 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
  • How to Change the Transparency of a Graph Plot in Matplotlib with Python?
    Matplotlib is a library in Python and it is numerical — mathematical extension for NumPy library. Pyplot is a state-based interface to a matplotlib module which provides a MATLAB-like interface. There are various plots that can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, e
    3 min read
  • How to Connect Scatterplot Points With Line in Matplotlib?
    Prerequisite: Scatterplot using Seaborn in Python Scatterplot can be used with several semantic groupings which can help to understand well in a graph. They can plot two-dimensional graphics that can be enhanced by mapping up to three additional variables while using the semantics of hue, size, and
    2 min read
  • How to add a legend to a scatter plot in Matplotlib ?
    In this article, we are going to add a legend to the depicted images using matplotlib module. We will use the matplotlib.pyplot.legend() method to describe and label the elements of the graph and distinguishing different plots from the same graph.  Syntax: matplotlib.pyplot.legend( ["title_1", "Titl
    2 min read
  • How to Set X-Axis Values in Matplotlib in Python?
    In this article, we will be looking at the approach to set x-axis values in matplotlib in a python programming language. The xticks() function in pyplot module of the Matplotlib library is used to set x-axis values. Syntax: matplotlib.pyplot.xticks(ticks=None, labels=None, **kwargs) xticks() functio
    2 min read
  • Matplotlib.axes.Axes.set_axis_on() in Python
    Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.
    2 min read
  • How to Add Axes to a Figure in Matplotlib with Python?
    Matplotlib is a library in Python used to create figures and provide tools for customizing it. It allows plotting different types of data, geometrical figures. In this article, we will see how to add axes to a figure in matplotlib. We can add axes to a figure in matplotlib by passing a list argument
    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