Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas.
Scatter plots are used to observe relationship between variables and uses dots to represent the relationship between them. Bubble plots are scatter plots with bubbles (color filled circles) rather than information focuses. Bubbles have various sizes dependent on another variable in the data. Likewise, Bubbles can be of various color dependent on another variable in the dataset.
Let us load the required module and the simplified Iris data as a Pandas Data frame:
Python3
# import all important libraries
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# load dataset
data= "https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv"
# convert to dataframe
df = pd.read_csv(data)
# display top most rows
df.head()
Output:

Scatter plot with Seaborn:
As stated earlier than, bubble is a unique form of scatter plot with bubbles as opposed to easy facts points in scatter plot. Let us first make a simple scatter plot the usage of Seaborn’s scatterplot() function.
Python3
# import all important libraries
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# load dataset
data = "https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv"
# convert to dataframe
df = pd.read_csv(data)
# display top most rows
df.head()
# depict scatterplot illustration
sns.set_context("talk", font_scale=1.1)
plt.figure(figsize=(8, 6))
sns.scatterplot(x="sepal.length",
y="sepal.width",
data=df)
# assign labels
plt.xlabel("Sepal.Length")
plt.ylabel("sepal.width")
Output:

Bubble plot with Seaborn scatterplot():
To make bubble plot in Seaborn, we are able to use scatterplot() function in Seaborn with a variable specifying size argument in addition to x and y-axis variables for scatter plot.
In this bubble plot instance, we have length= ”body_mass_g”. And this will create a bubble plot with unique bubble sizes based at the body length variable.
Python3
# import all important libraries
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# load dataset
data = "https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv"
# convert to dataframe
df = pd.read_csv(data)
# display top most rows
df.head()
# depict scatter plot illustration
sns.set_context("talk", font_scale=1.1)
plt.figure(figsize=(10, 6))
sns.scatterplot(x="petal.length",
y="petal.width",
data=df)
# Put the legend out of the figure
plt.legend(bbox_to_anchor=(1.01, 1), borderaxespad=0)
plt.xlabel("petal.length")
plt.ylabel("petal.width")
plt.tight_layout()
plt.savefig("Bubble_plot_Seaborn_scatterplot.png",
format='png', dpi=150)
Output:
The below example depicts a bubble plot having colored bubbles:
Python3
# import all important libraries
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# load dataset
data= "https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv"
# convert to dataframe
df = pd.read_csv(data)
# display top most rows
df.head()
# depict bubble plot illustration
sns.set_context("talk", font_scale=1.2)
plt.figure(figsize=(10,6))
sns.scatterplot(x='petal.length',
y='petal.width',
sizes=(20,500),
alpha=0.5,
data= df)
# Put the legend out of the figure
plt.legend(bbox_to_anchor=(1.01, 1),borderaxespad=0)
# assign labels
plt.xlabel("Sepal.length")
plt.ylabel("Sepal.width")
# assign title
plt.title("Bubble plot in Seaborn")
# adjust layout
plt.tight_layout()
Output:

Bubble plot with explicit size ranges Seaborn scatterplot()
We can alter the air bubble plot made with Seaborn without any problem. Something that we notice from the bubble plot above is that the bubble size range is by all accounts little. It will be extraordinary in the event that we could differ the littlest and biggest bubble sizes.
With the contention sizes in Seaborn's scatterplot() work, we can indicate ranges for the bubble sizes. In this air pocket plot model underneath, we utilized sizes=(20,500).
Python3
# import all important libraries
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# load dataset
data = "https://gist.githubusercontent.com/netj/8836201/raw/6f9306ad21398ea43cba4f7d537619d0e07d5ae3/iris.csv"
# convert to dataframe
df = pd.read_csv(data)
# display top most rows
df.head()
# depict bubble plot illustration
sns.set_context("talk", font_scale=1.2)
plt.figure(figsize=(10, 6))
sns.scatterplot(x='sepal.length',
y='sepal.width',
# size="body_mass_g",
sizes=(20, 500),
alpha=0.5,
hue='variety',
data=df)
# Put the legend out of the figure
plt.legend(bbox_to_anchor=(1.01, 1), borderaxespad=0)
# Put the legend out of the figure
plt.xlabel("sepal.length")
plt.ylabel("sepal.width")
plt.title("Bubble plot with Colors in Seaborn")
plt.tight_layout()
Output:
Presently our bubble plot looks much better with the lowest bubble comparing to the lowest weight and the greatest bubble relates to the biggest weight. At the point when you have more factors in the information, we can shade the bubble by the fourth factor. To color the bubble plot by a variable, we determine tone contention.
Similar Reads
Circular Bar Plot in seaborn Circular bar plots, also known as radial bar charts or circular histograms, are a visually appealing way to display data. In this article, we'll explore how to create circular bar plots using the Seaborn library in Python. What are circular bar plots?In contrast to conventional bar charts, which dis
5 min read
Circular Bar Plot in seaborn Circular bar plots, also known as radial bar charts or circular histograms, are a visually appealing way to display data. In this article, we'll explore how to create circular bar plots using the Seaborn library in Python. What are circular bar plots?In contrast to conventional bar charts, which dis
5 min read
Types Of Seaborn Plots Seaborn is a Python data visualization library based on Matplotlib that provides a high-level interface for drawing attractive and informative statistical graphics. It is built on top of matplotlib and integrates with pandas data structures making it an ideal choice for visualizing data from data fr
7 min read
Python - seaborn.regplot() method Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are ? Default Matplotlib parametersWorking with data fram
3 min read
seaborn.countplot() in Python seaborn.countplot() is a function in the Seaborn library in Python used to display the counts of observations in categorical data. It shows the distribution of a single categorical variable or the relationship between two categorical variables by creating a bar plot. Example:Pythonimport seaborn as
8 min read
Python - seaborn.pairplot() method seaborn.pairplot() method is used for visualizing relationships between multiple variables in a dataset. By creating a grid of scatter plots it helps to identify how different features interact with each other to identify patterns, correlations and trends in data. In this article, we will see how to
3 min read