
- Matplotlib - Home
- Matplotlib - Introduction
- Matplotlib - Vs Seaborn
- Matplotlib - Environment Setup
- Matplotlib - Anaconda distribution
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - Simple Plot
- Matplotlib - Saving Figures
- Matplotlib - Markers
- Matplotlib - Figures
- Matplotlib - Styles
- Matplotlib - Legends
- Matplotlib - Colors
- Matplotlib - Colormaps
- Matplotlib - Colormap Normalization
- Matplotlib - Choosing Colormaps
- Matplotlib - Colorbars
- Matplotlib - Working With Text
- Matplotlib - Text properties
- Matplotlib - Subplot Titles
- Matplotlib - Images
- Matplotlib - Image Masking
- Matplotlib - Annotations
- Matplotlib - Arrows
- Matplotlib - Fonts
- Matplotlib - Font Indexing
- Matplotlib - Font Properties
- Matplotlib - Scales
- Matplotlib - LaTeX
- Matplotlib - LaTeX Text Formatting in Annotations
- Matplotlib - PostScript
- Matplotlib - Mathematical Expressions
- Matplotlib - Animations
- Matplotlib - Celluloid Library
- Matplotlib - Blitting
- Matplotlib - Toolkits
- Matplotlib - Artists
- Matplotlib - Styling with Cycler
- Matplotlib - Paths
- Matplotlib - Path Effects
- Matplotlib - Transforms
- Matplotlib - Ticks and Tick Labels
- Matplotlib - Radian Ticks
- Matplotlib - Dateticks
- Matplotlib - Tick Formatters
- Matplotlib - Tick Locators
- Matplotlib - Basic Units
- Matplotlib - Autoscaling
- Matplotlib - Reverse Axes
- Matplotlib - Logarithmic Axes
- Matplotlib - Symlog
- Matplotlib - Unit Handling
- Matplotlib - Ellipse with Units
- Matplotlib - Spines
- Matplotlib - Axis Ranges
- Matplotlib - Axis Scales
- Matplotlib - Axis Ticks
- Matplotlib - Formatting Axes
- Matplotlib - Axes Class
- Matplotlib - Twin Axes
- Matplotlib - Figure Class
- Matplotlib - Multiplots
- Matplotlib - Grids
- Matplotlib - Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Subplots() Function
- Matplotlib - Subplot2grid() Function
- Matplotlib - Anchored Artists
- Matplotlib - Manual Contour
- Matplotlib - Coords Report
- Matplotlib - AGG filter
- Matplotlib - Ribbon Box
- Matplotlib - Fill Spiral
- Matplotlib - Findobj Demo
- Matplotlib - Hyperlinks
- Matplotlib - Image Thumbnail
- Matplotlib - Plotting with Keywords
- Matplotlib - Create Logo
- Matplotlib - Multipage PDF
- Matplotlib - Multiprocessing
- Matplotlib - Print Stdout
- Matplotlib - Compound Path
- Matplotlib - Sankey Class
- Matplotlib - MRI with EEG
- Matplotlib - Stylesheets
- Matplotlib - Background Colors
- Matplotlib - Basemap
- Matplotlib - Event Handling
- Matplotlib - Close Event
- Matplotlib - Mouse Move
- Matplotlib - Click Events
- Matplotlib - Scroll Event
- Matplotlib - Keypress Event
- Matplotlib - Pick Event
- Matplotlib - Looking Glass
- Matplotlib - Path Editor
- Matplotlib - Poly Editor
- Matplotlib - Timers
- Matplotlib - Viewlims
- Matplotlib - Zoom Window
- Matplotlib Widgets
- Matplotlib - Cursor Widget
- Matplotlib - Annotated Cursor
- Matplotlib - Buttons Widget
- Matplotlib - Check Buttons
- Matplotlib - Lasso Selector
- Matplotlib - Menu Widget
- Matplotlib - Mouse Cursor
- Matplotlib - Multicursor
- Matplotlib - Polygon Selector
- Matplotlib - Radio Buttons
- Matplotlib - RangeSlider
- Matplotlib - Rectangle Selector
- Matplotlib - Ellipse Selector
- Matplotlib - Slider Widget
- Matplotlib - Span Selector
- Matplotlib - Textbox
- Matplotlib Plotting
- Matplotlib - Line Plots
- Matplotlib - Area Plots
- Matplotlib - Bar Graphs
- Matplotlib - Histogram
- Matplotlib - Pie Chart
- Matplotlib - Scatter Plot
- Matplotlib - Box Plot
- Matplotlib - Arrow Demo
- Matplotlib - Fancy Boxes
- Matplotlib - Zorder Demo
- Matplotlib - Hatch Demo
- Matplotlib - Mmh Donuts
- Matplotlib - Ellipse Demo
- Matplotlib - Bezier Curve
- Matplotlib - Bubble Plots
- Matplotlib - Stacked Plots
- Matplotlib - Table Charts
- Matplotlib - Polar Charts
- Matplotlib - Hexagonal bin Plots
- Matplotlib - Violin Plot
- Matplotlib - Event Plot
- Matplotlib - Heatmap
- Matplotlib - Stairs Plots
- Matplotlib - Errorbar
- Matplotlib - Hinton Diagram
- Matplotlib - Contour Plot
- Matplotlib - Wireframe Plots
- Matplotlib - Surface Plots
- Matplotlib - Triangulations
- Matplotlib - Stream plot
- Matplotlib - Ishikawa Diagram
- Matplotlib - 3D Plotting
- Matplotlib - 3D Lines
- Matplotlib - 3D Scatter Plots
- Matplotlib - 3D Contour Plot
- Matplotlib - 3D Bar Plots
- Matplotlib - 3D Wireframe Plot
- Matplotlib - 3D Surface Plot
- Matplotlib - 3D Vignettes
- Matplotlib - 3D Volumes
- Matplotlib - 3D Voxels
- Matplotlib - Time Plots and Signals
- Matplotlib - Filled Plots
- Matplotlib - Step Plots
- Matplotlib - XKCD Style
- Matplotlib - Quiver Plot
- Matplotlib - Stem Plots
- Matplotlib - Visualizing Vectors
- Matplotlib - Audio Visualization
- Matplotlib - Audio Processing
- Matplotlib Useful Resources
- Matplotlib - Quick Guide
- Matplotlib - Cheatsheet
- Matplotlib - Useful Resources
- Matplotlib - Discussion
Matplotlib - Textbox
A textbox is an area in a document or on a screen where you can type or display text. It is like a little box where you can input or output words, sentences, or paragraphs. Think of it like this −
Input Textbox − When you see a blank area on a form or a website where you can type your name, email, or any other information, that is a textbox. You can click on it and start typing.
Output Textbox − When you see a section of a webpage or document where there is text displayed, like a message or a description, that's also a textbox. It just shows text instead of letting you type into it.

Textbox in Matplotlib
In Matplotlib, a Textbox is a graphical element used to display text within a plot, providing additional information or annotations. It allows you to include descriptive text, labels, or explanations directly on the plot.
You can create a textbox in Matplotlib using the text() function. In Matplotlib, the function used to create a textbox is plt.text(). This function allows you to add text directly to a plot, specifying the text content and its position within the plot. Additionally, you can customize various attributes of the textbox, such as font style, size, color, alignment, and background color, to suit their visualization needs.
Basic Text Box
A basic text box in Matplotlib is a simple way to add text to a plot. It allows you to include labels or annotations directly onto the plot. You can specify the content of the text and its position within the plot using the text() function.
Example
In the following example, we are creating a basic text box with the text "Sample Text Box" at the coordinates (2, 10) on the plot −
import matplotlib.pyplot as plt # Creating a plot plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) # Adding a basic text box plt.text(2, 10, 'Sample Text Box', fontsize=12, bbox=dict(facecolor='yellow', alpha=0.5)) # Displaying the plot plt.show()
Output
Following is the output of the above code −

Rounded Text Box
A rounded text box in Matplotlib is a variation of a basic text box with rounded corners. It allows you to add text to a plot within a rectangular-shaped box, but with softened corners.
Example
In here, we are creating a rounded text box with the text "Rounded Text Box" at the coordinates (2, 10) on the plot −
import matplotlib.pyplot as plt # Creating a plot plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) # Adding a rounded text box plt.text(2, 10, 'Rounded Text Box', fontsize=12, bbox=dict(facecolor='lightblue', alpha=0.5, edgecolor='blue', boxstyle='round,pad=0.5')) # Displaying the plot plt.show()
Output
On executing the above code we will get the following output −

Custom Text Box with Arrow
A custom text box with an arrow in Matplotlib is a special type of annotation that combines a text box with an arrow pointing to a specific location on a plot. It is a way to draw attention to particular features or data points within a plot.
Example
The following example creates a custom text box with an arrow pointing to the text "Custom Text Box" at the coordinates (2, 10) on the plot −
import matplotlib.pyplot as plt # Creating a plot plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) # Adding a custom text box with arrow plt.annotate('Custom Text Box', xy=(2, 10), xytext=(3, 15), arrowprops=dict(facecolor='orange', shrink=0.05)) # Displaying the plot plt.show()
Output
After executing the above code, we get the following output −

Multiline Text Box
In Matplotlib, a multiline text box allows you to include multiple lines of text within a single annotation box on a plot. This feature is useful for adding longer explanations, descriptions, or labels that span across multiple lines.
Example
Now, we are creating a multiline text box with three lines of text at the coordinates (2, 10) on the plot. We separate each line by "\n" −
import matplotlib.pyplot as plt # Creating a plot plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) # Adding a multiline text box plt.text(2, 10, 'Line 1\nLine 2\nLine 3', fontsize=12, bbox=dict(facecolor='lightgrey', alpha=0.5)) # Displaying the plot plt.show()
Output
On executing the above code we will get the following output −
