
- 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 - Ellipse Demo
An ellipse is a geometric shape that looks like a slightly stretched circle. It has a curved outline, and unlike a circle, it has two different diameters; a longer one called the major axis and a shorter one called the minor axis. The center of the ellipse is a point around which the shape is symmetrically balanced.

Ellipse Demo in Matplotlib
We can create an ellipse demo in Matplotlib using the "Ellipse" class in the "matplotlib.patches" module. The Ellipse class allows you to define the center, width and height (major and minor axes), angle of rotation, and other properties of the ellipse.
The matplotlib.patches.Ellipse Class
The matplotlib.patches.Ellipse class constructs an elliptical patch in Matplotlib plots. It takes parameters for the center coordinates, width (major axis length), height (minor axis length), and angle (rotation angle in degrees) and returns an ellipse instance.
Following is the syntax for creating an ellipse using the Ellipse class in Matplotlib −
patches.Ellipse(xy, width, height, angle=0.0, **kwargs)
Where,
- xy is the center of the ellipse as a tuple (x, y).
- width is the width of the ellipse.
- height is the height of the ellipse.
- angle (optional) is the rotation angle of the ellipse in degrees (default is 0.0).
- **kwargs is the additional keyword arguments for customization.
Let us start by creating a rotated ellipse.
Rotated Ellipse
We can create a rotated ellipse in Matplotlib using the Ellipse class from the matplotlib.patches module. The rotation angle allows the ellipse to be tilted or rotated around its center. This can be achieved by specifying the angle parameter when creating the Ellipse object.
Example
In the following example, we are creating a rotated ellipse with a 45-degree angle. The ellipse has a width of 3 units, a height of 2 units, an edgecolor of blue ('b'), and no face color −
import matplotlib.pyplot as plt import matplotlib.patches as patches fig, ax = plt.subplots() # Rotated ellipse ellipse = patches.Ellipse((0, 0), 3, 2, angle=45, edgecolor='b', facecolor='none') ax.add_patch(ellipse) plt.title('Rotated Ellipse') # Setting axis to be equal plt.axis('equal') plt.show()
Output
After executing the above code, we get the following output −

Ellipse with Custom Color
We can customize the color of an ellipse as well in matplotlib. We achieve this by specifying the desired edge and face colors when creating the Ellipse object. The "edgecolor" parameter determines the color of the ellipse's outline, while the "facecolor" parameter sets the color of its interior.
Example
In here, we are creating an ellipse having a green ('g') edge color and a yellow face color, providing a colorful appearance −
import matplotlib.pyplot as plt import matplotlib.patches as patches fig, ax = plt.subplots() # Ellipse with custom colors ellipse = patches.Ellipse((0, 0), 3, 2, edgecolor='g', facecolor='yellow') ax.add_patch(ellipse) plt.title('Ellipse with Custom Colors') # Setting axis to be equal plt.axis('equal') plt.show()
Output
Following is the output of the above code −

Multiple Ellipses
We can also add multiple ellipses to a single plot by creating multiple instances of the Ellipse class. This allows us to represent various shapes simultaneously, each with its own unique characteristics and positions.
Example
Now, we are creating two ellipses "ellipse1" and "ellipse2" with different sizes and colors, and adding them to the axes −
import matplotlib.pyplot as plt import matplotlib.patches as patches fig, ax = plt.subplots() # Multiple ellipses ellipse1 = patches.Ellipse((0, 0), 3, 2, edgecolor='r', facecolor='none') ellipse2 = patches.Ellipse((0, 0), 2, 4, edgecolor='b', facecolor='none') ax.add_patch(ellipse1) ax.add_patch(ellipse2) plt.title('Multiple Ellipses') # Setting axis to be equal plt.axis('equal') plt.show()
Output
Output of the above code is as follows −

Ellipse with Transparency
You can customize the transparency, often referred to as alpha blending, of an ellipse, by setting the alpha parameter when creating the Ellipse object. This parameter controls the opacity of the ellipse, allowing us to create semi-transparent shapes that overlay with other elements in the plot.
Example
In the example below, we are creating an ellipse with a pink face color and 10% transparency (alpha=0.1) −
import matplotlib.pyplot as plt import matplotlib.patches as patches fig, ax = plt.subplots() # Ellipse with transparency ellipse = patches.Ellipse((0, 0), 3, 2, edgecolor='r', facecolor='pink', alpha=0.1) ax.add_patch(ellipse) plt.title('Ellipse with Transparency') # Setting axis to be equal plt.axis('equal') plt.show()
Output
The output obtained is as shown below −
