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:
Matplotlib - Textbox Widgets
Next article icon

Matplotlib - Cursor Widget

Last Updated : 15 Mar, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Matplotlib is a Data Visualization library in python. It consists of many widgets that are designed to work for any of the GUI backends. Some examples of widgets in matplotlib are Button, CheckButtons, RadioButtons, Cursor, and TextBox. In this article, the Cursor Widget of Matplotlib library has been discussed.

A Cursor spans the axes horizontally and/or vertically and moves with the mouse cursor. 

Syntax: Cursor(ax, horizOn=True, vertOn=True, useblit=False, **lineprops)

Parameters:

  • ax : Axes to attach the cursor to.
  • Optional Parameters:
  • horizOn : To draw the horizontal line(default: True).
  • vertOn : To draw the vertical line(default: True).
  • useblit : Use blitting for faster drawing if supported by the backend(default: False).
  • **lineprops: Line properties to control appearance of the lines(linewidth, color).

Example 1:

Python3
# importing cursor widget from matplotlib from matplotlib.widgets import Cursor import matplotlib.pyplot as plt import numpy as np  fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])  num = 100 x = np.random.rand(num) y = np.random.rand(num)  ax.scatter(x, y, c='blue') ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis')  cursor = Cursor(ax, color='green', linewidth=2) plt.show() 

Output:

In the above output, the cursor can be moved horizontally and vertically throughout the matplotlib axes. We can just drag the cursor wherever necessary.

MultiCursor

MultiCursor is used to show cursor on multiple plots at the same time i.e., Cursor is shared between multiple axes.

Syntax:

MultiCursor(canvas, axes, useblit=True, horizOn=False, vertOn=True, **lineprops)

Example:

Python3
# Import MultiCursor from matplotlib from matplotlib.widgets import MultiCursor import matplotlib.pyplot as plt import numpy as np  fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True)  x = np.linspace(-np.pi, np.pi, 256, endpoint=True) y = np.sin(x) z = np.cos(x)  ax1.plot(x, y, label="sin function") ax1.legend(loc="upper right") ax2.plot(x, z, label="cos function")  multi = MultiCursor(fig.canvas, (ax1, ax2), color='g', lw=2,                     horizOn=False, vertOn=True)  ax2.legend(loc="upper right") plt.show() 

Output:

Example:

Python3
from matplotlib.widgets import MultiCursor import matplotlib.pyplot as plt import numpy as np  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))  x1 = ['Telugu', 'Hindi', 'English',       'Maths', 'Science', 'Social'] y1 = [45, 34, 30, 45, 50, 38] y2 = [36, 28, 30, 45, 38, 50]  labels = ["in 2020", "in 2021"]  l1 = ax1.plot(x1, y1, 'o', color="green") l2 = ax2.plot(x1, y2, 'o', color="blue")  ax1.set_yticks(np.arange(0, 51, 5)) ax2.set_yticks(np.arange(0, 51, 5))  ax1.set_ylabel('Number of students passed', fontsize=15)  fig.legend([l1, l2], labels=labels, loc="upper right") cursor = MultiCursor(fig.canvas, (ax1, ax2), color='r',                      lw=2, horizOn=True, vertOn=True)  plt.subplots_adjust(right=0.9) plt.show() 

Output:


Next Article
Matplotlib - Textbox Widgets

G

greeshmanalla
Improve
Article Tags :
  • Python
  • Python-matplotlib
Practice Tags :
  • python

Similar Reads

  • Matplotlib - Checkbox Widget
    In this article, We are going to see the use of these checkboxes in matplotlib plots to make our plot more interactive. Checkbox widget offers us the freedom to make our plot more interactive. By using checkboxes we can perform on-tick events which on ticking the checkbox will trigger some event. We
    2 min read
  • Matplotlib - Slider Widget
    Matplotlib provides several widgets to make interactive plots. Among these widgets, the Slider widget is discussed here. The Slider provides control over the visual properties of the plot.  Slider() is used to place a slider representing a floating point range in a plot on provided axes. Syntax: cla
    4 min read
  • Matplotlib - Lasso Selector Widget
    Matplotlib provides us with a variety of widgets. In this article, we will be learning about Lasso Selector Widget Demo. A Lasso Selector Widget is a tool that helps us to make a selection curve of arbitrary space. Approach #1 We will be adding the axes manually to our plot and then use the lasso-se
    3 min read
  • Matplotlib - Textbox Widgets
    In this article, we are going to see matplotlib's textbox widget. Matplotlib is a plotting library for the Python programming language. In this article, we will try to plot a graph for different powers(e.g. t^2, t^3, t^9, etc.) using textbox widget. The Textbox is a widget that accepts input from th
    2 min read
  • Cross-Hair Cursor in Matplotlib
    A cross-hair cursor is a precision tool designed to enhance accuracy by marking a specific point on the screen with two intersecting perpendicular lines. Commonly used in design, gaming, and analysis, the cross-hair cursor enables exact placement, measurement, or alignment. Example: Imagine analyzin
    10 min read
  • PYGLET – Setting Cursor
    In this article we will see how we can set special cursor to the window in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows ma
    2 min read
  • Matplotlib Tutorial
    Matplotlib is an open-source visualization library for the Python programming language, widely used for creating static, animated and interactive plots. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, Qt, GTK and wxPython. It
    5 min read
  • How to embed Matplotlib charts in Tkinter GUI?
    Prerequisite: Introduction to Tkinter | Introduction to Matplotlib When Matplotlib is used from Python shell, the plots are displayed in a default window. The plots can be embedded in many graphical user interfaces like wxpython, pygtk, or Tkinter. These various options available as a target for the
    3 min read
  • Python Tkinter - Create Button Widget
    The Tkinter Button widget is a graphical control element used in Python's Tkinter library to create clickable buttons in a graphical user interface (GUI). It provides a way for users to trigger actions or events when clicked. Note: For more reference, you can read our article: What is WidgetsPython
    6 min read
  • Python Tkinter - Canvas Widget
    Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in python. Tkinter uses an object-oriented approach to make GUIs.Note: For more information, refer to Python GUI – tkinter Canvas widget The Canvas widget l
    3 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