
- 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 - Bubble Plots
A bubble plot is a type of scatter plot where each data point is represented by a marker (generally a circle or "bubble") on a two-dimensional axis. In addition to the traditional x and y coordinates, a third variable is used to determine the size of the marker, creating the illusion of three dimensions. The size of each bubble provides additional information about the data point.

Bubble Plots in Matplotlib
We can create a bubble plot in Matplotlib using the scatter() function. This function allows us to customize the appearance of the bubble plot, including markers, colors, and sizes of the points.
This function takes two arrays or lists as input, where each array corresponds to the values of a different variable. The points are then plotted on a set of axes, with the position of each point determined by the values of the two variables.
The scatter() Function
In Matplotlib, a bubble plot can be created using the scatter() function, where the "s" parameter is used to set the size of the markers (bubbles). The scatter function allows you to represent three dimensions of data: the x and y coordinates determine the position of the markers, while the s parameter controls their size.
Following is the syntax of the scatter() function in Matplotlib −
plt.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, ...)
Where,
- x and y is an array or list representing the x-coordinate and y-coordinate values respectively of the data points.
- s (optional) is the size of the markers.
- c (optional) is the color of the markers.
- marker (optional) is the marker style.
- cmap (optional) is the colormap for mapping the color of the markers.
- norm (optional) is the normalize object for mapping the data values to the colormap.
- vmin, vmax (optional) is the minimum and maximum values for normalizing the colormap.
These are just a few parameters; there are more optionals parameters available for customization.
Basic Bubble Plot
In a Basic Bubble Plot using Matplotlib, we represent data points as bubbles on a two-dimensional plane. The position of each bubble is determined by its corresponding x and y coordinates, while the size of the bubble indicates a third dimension, representing a quantitative variable.
Example
In the following example, we are creating a basic bubble plot using plt.scatter() function. The size of each bubble is determined by the "sizes" list, and the "alpha" parameter controls the transparency. The edges of the bubbles are set to "white" −
import matplotlib.pyplot as plt # Data x = [1, 2, 3, 4, 5] y = [10, 20, 15, 25, 30] sizes = [50, 100, 75, 120, 90] # Creating a bubble plot plt.scatter(x, y, s=sizes, alpha=0.5, edgecolors='w', linewidth=2) # Adding title and axis labels plt.title('Basic Bubble Plot') plt.xlabel('X-axis') plt.ylabel('Y-axis') # Displaying the plot plt.show()
Output
After executing the above code, we get the following output −

Color-Mapped Bubble Plot
We enhance the basic bubble plot in Matplotlib by using a color dimension to create a Color-Mapped Bubble Plot. In this type of plot, each bubble not only conveys information through its x and y coordinates but also displays a unique color, creating a color-mapped effect. This coloring is often associated with a third variable, adding another layer of meaning to the plot.
We construct the Color-Mapped Bubble Plot using the plt.scatter() function, with the "c" parameter specifying the color mapping.
Example
In here, we are creating a bubble plot by adding color to each bubble. The "colors" list assigns a unique color to each bubble, creating a color-mapped effect. We are outlining the bubbles with black edges −
import matplotlib.pyplot as plt # Data x = [1, 2, 3, 4, 5] y = [10, 20, 15, 25, 30] sizes = [50, 100, 75, 120, 90] colors = ['red', 'green', 'blue', 'orange', 'purple'] # Color-Mapped Bubble Plot plt.scatter(x, y, s=sizes, c=colors, alpha=0.8, edgecolors='k', linewidth=2) # Adding title and axis labels plt.title('Color-Mapped Bubble Plot') plt.xlabel('X-axis') plt.ylabel('Y-axis') # Displaying the plot plt.show()
Output
Following is the output of the above code −

Customized Bubble Plot
We can also customize the appearance of the bubbles in a bubble plot. This is achieved by changing the marker style, edge color, transparency etc. using various parameters in the plt.scatter() function.
Example
Now, we are customizing the bubble plot by changing the marker style to a triangle (marker='^') −
import matplotlib.pyplot as plt # Data x = [1, 2, 3, 4, 5] y = [10, 20, 15, 25, 30] sizes = [50, 100, 75, 120, 90] colors = ['red', 'green', 'blue', 'orange', 'purple'] # Customized Bubble Plot plt.scatter(x, y, s=sizes, c=colors, alpha=0.8, edgecolors='k', linewidth=2, marker='^') # Adding title and axis labels plt.title('Customized Bubble Plot') plt.xlabel('X-axis') plt.ylabel('Y-axis') # Displaying the plot plt.show()
Output
Output of the above code is as follows −

Bubble Plot with Annotations
In a bubble plot with annotations using Matplotlib, data points are represented as bubbles, with the size of each bubble corresponding to a specific numerical value (annotations). These annotations provide textual information associated with each data point.
Example
In the example below, we are adding annotations to the bubble plot, displaying the exact size value of each bubble. We are using the plt.annotate() function to place text labels near each bubble −
import matplotlib.pyplot as plt # Data x = [1, 2, 3, 4, 5] y = [10, 20, 15, 25, 30] sizes = [50, 100, 75, 120, 90] # Bubble Plot with Annotations plt.scatter(x, y, s=sizes, alpha=0.5, edgecolors='w', linewidth=2) for i, txt in enumerate(sizes): # Adding annotations plt.annotate(f'{int(txt)}', (x[i], y[i]), textcoords="offset points", xytext=(0, -15), ha='center') # Adding title and axis labels plt.title('Bubble Plot with Annotations') plt.xlabel('X-axis') plt.ylabel('Y-axis') # Displaying the plot plt.show()
Output
The output obtained is as shown below −
