
- 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 - Mmh Donuts
A donut is a circular pastry with a hole in the center, giving it a classic ring shape. The outer surface of donut is usually smooth and glazed, adding a shiny finish. The shape defines a perfect balance of curvature.

Mmh Donuts in Matplotlib
In Matplotlib, we can create a donut shape by drawing circular wedges for both the outer and inner circles. We can use the Wedge class in the "matplotlib.patches" module to define these circles and combine them to create a donut appearance.
You can customize the donut by adjusting the center, inner and outer radii, and colors, and remember to set equal aspect ratios for a circular look.
The matplotlib.patches.Wedge Class
The matplotlib.patches.Wedge class in Matplotlib is used to make wedge-shaped patches, which are like circular sectors. These wedges are created by specifying their center coordinates, inner and outer radii, and angular extent. By instantiating objects of this class, you can easily add these wedge shapes to your Matplotlib plot.
Following is the syntax for creating a donut using the Wedge class in Matplotlib −
matplotlib.patches.Wedge(center, r, theta1, theta2, width=None, **kwargs)
Where,
- centeris the tuple (x, y) representing the center coordinates of the wedge.
- r is the outer radius of the wedge.
- theta1is the starting angle of the wedge in degrees.
- theta2 is the ending angle of the wedge in degrees.
- width (optional) is the width of the wedge (default is None).
- **kwargs is the additional keyword arguments for customizing the wedge appearance.
Let us start by creating a basic donut.
Basic Donut
You can create a basic donut shape in Matplotlib using the matplotlib.patches.Wedge class. The donut is defined by specifying its center coordinates, outer and inner radii, and the width of the ring. The resulting plot displays a circular ring with a different face color and edge color, representing a basic donut.
Example
In the following example, we are creating a basic donut shape using the matplotlib.patches.Wedge class. We are first defining the outer and inner radii as "0.8" and "0.4" respectively. We are then passing the arguments such as center coordinates, outer radius, inner radius, and width to the patches.wedge() function −
import matplotlib.pyplot as plt import matplotlib.patches as patches # Creating a figure and axis fig, ax = plt.subplots() # Defining the outer and inner radii outer_radius = 0.8 inner_radius = 0.4 # Creating a Wedge representing the donut donut = patches.Wedge((0, 0), outer_radius, 0, 360, width=outer_radius - inner_radius, facecolor='brown', edgecolor='black') # Adding the donut to the plot ax.add_patch(donut) # Setting equal aspect ratio for a circular look ax.set_aspect('equal', adjustable='box') # Display the plot plt.title('Basic Donut') # Adjust the x-axis limit plt.xlim(-1, 1) # Adjust the y-axis limit plt.ylim(-1, 1) plt.show()
Output
After executing the above code, we get the following output −

Double Donut
You can create a double donut as well in matplotlib by drawing two concentric circles. To achieve this, define each donut by specifying the center coordinates, outer and inner radii, and width. The resulting plot will displays two distinct donuts with different face colors and edges.
Example
In here, we are creating two concentric donuts in the same plot. We are defining each donut by its unique outer and inner radii, and applying distinct face colors and edge colors −
import matplotlib.pyplot as plt import matplotlib.patches as patches # Creating a figure and axis fig, ax = plt.subplots() # Defining the radii for the outer and inner circles of the first donut outer_radius_1 = 0.8 inner_radius_1 = 0.4 # Creating a Wedge representing the first donut donut1 = patches.Wedge((0, 0), outer_radius_1, 0, 360, width=outer_radius_1 - inner_radius_1, facecolor='brown', edgecolor='black') # Defining the radii for the outer and inner circles of the second donut outer_radius_2 = 0.6 inner_radius_2 = 0.2 # Creating a Wedge representing the second donut donut2 = patches.Wedge((0, 0), outer_radius_2, 0, 360, width=outer_radius_2 - inner_radius_2, facecolor='lightgreen', edgecolor='black') # Adding the donuts to the plot ax.add_patch(donut1) ax.add_patch(donut2) # Setting equal aspect ratio for a circular look ax.set_aspect('equal', adjustable='box') # Displaying the plot plt.title('Double Donut') plt.xlim(-1, 1) plt.ylim(-1, 1) plt.show()
Output
Following is the output of the above code −

Patterned Donut
You can also create a patterned donut with a textured appearance using the matplotlib.patches.Wedge class. This class allows you to specify the center coordinates, outer and inner radii, as well as the width of the donut. To enhance its visual appeal, fill the donut's face with a crosshatch pattern ('xx') using the hatch parameter.
The resulting plot displays a donut with a distinct style, combining the circular shape with a specific hatch pattern.
Example
Now, we are creating a donut with a light yellow face color, a black edge, and 'xx' hatch patterns applied to its face −
import matplotlib.pyplot as plt import matplotlib.patches as patches fig, ax = plt.subplots() outer_radius = 0.8 inner_radius = 0.4 # Creating a Wedge representing the donut donut = patches.Wedge((0, 0), outer_radius, 0, 360, width=outer_radius - inner_radius, edgecolor='black', hatch='xx', facecolor='yellow') ax.add_patch(donut) ax.set_aspect('equal', adjustable='box') plt.title('Patterned Donut') plt.xlim(-1, 1) plt.ylim(-1, 1) plt.show()
Output
Output of the above code is as follows −

Custom Donut
We can create a unique donut shape by customizing it using the matplotlib.patches.Wedge class. We can provide distinct angular extent to the donut, forming a partial circle. To enhance the shape visually, we can style the donut's edge with a dashed line ('--').
Example
In the example below, we are customizing the donut with a specific angular extent, creating a partial circle. We are styling the donut with a light blue face color, a dark blue edge, and a dashed linestyle as shown below −
import matplotlib.pyplot as plt import matplotlib.patches as patches fig, ax = plt.subplots() outer_radius = 0.8 inner_radius = 0.4 # Creating a Wedge representing the custom donut with a specific angular extent donut = patches.Wedge((0, 0), outer_radius, 45, 315, width=outer_radius - inner_radius, edgecolor='darkblue', linestyle='--', facecolor='lightblue') # Adding the donut to the plot ax.add_patch(donut) ax.set_aspect('equal', adjustable='box') plt.title('Custom Donut') plt.xlim(-1, 1) plt.ylim(-1, 1) plt.show()
Output
The output obtained is as shown below −
