How To Change Marker Size In Seaborn Scatterplot
Last Updated :
12 Jun, 2024
In Scatterplot Marker Size is important as it visually represents the data points' significance or weightage. To change the marker size in a Seaborn scatterplot, we have several options depending on whether you want a uniform size for all markers or varying sizes based on data values. In this article, we will explore two different methods/approaches to change marker size in seaborn scatterplot in Python.
Modifying Marker Size In Seaborn Scatterplot
Below are the possible approaches to change marker size in seaborn scatterplot in Python.
Method 1: Using the size
Parameter in scatterplot()
In this example, we are using the size parameter in the sns.scatterplot() function to change the marker size in a Seaborn scatterplot. The size parameter takes a column name from the data frame (data) that specifies the marker sizes. By assigning the size parameter to the 'size' column in our data, we can control the marker size based on the values in that column.
Syntax:
sns.scatterplot(x='x_column_name', y='y_column_name', size='size_column_name', data=data_frame)
- x_column_name: The column name in your DataFrame that contains the x-axis data.
- y_column_name: The column name in your DataFrame that contains the y-axis data.
- size_column_name: The column name in your DataFrame that contains the marker size data.
- data_frame: The DataFrame containing your data.
Python
import seaborn as sns
import matplotlib.pyplot as plt
data = {
'x': [1, 2, 3, 4, 5],
'y': [10, 15, 12, 17, 20],
'size': [100, 200, 300, 400, 500] # Marker size data
}
# Create a scatterplot with marker size
sns.scatterplot(x='x', y='y', size='size', data=data)
# Show the plot
plt.show()
Output:

Method 2: Using Matplotlib's scatter
Function with the s
Parameter
In this example, we are using the plot function from Matplotlib along with Seaborn's scatterplot function. First, we create the initial scatterplot using Seaborn to set up the axes and color scheme based on the 'category' column. Then, we use Matplotlib's scatter function to overlay markers on the plot, specifying the marker shape ('o' for circles) and the marker size (s=data['size']) based on the 'size' column in our data.
Syntax:
plt.scatter(x_values, y_values, s=marker_sizes, marker='marker_shape')
- x_values: The x-axis values for the data points.
- y_values: The y-axis values for the data points.
- marker_sizes: An array or list containing the marker sizes corresponding to each data point.
- marker_shape: The shape of the marker, such as 'o' for circles, '^' for triangles, 's' for squares, etc.
Python
import seaborn as sns
import matplotlib.pyplot as plt
data = {
'x': [1, 2, 3, 4, 5],
'y': [10, 20, 30, 40, 50],
'category': ['A', 'B', 'A', 'B', 'A'],
'size': [100, 150, 200, 250, 300]
}
# Creating a scatterplot with marker size based on a column
sns.scatterplot(x='x', y='y', hue='category', data=data)
plt.scatter(data['x'], data['y'], s=data['size'], marker='o')
plt.title('Scatterplot with Marker Size')
plt.show()
Output:
Using Matplotlib's scatter Function with the s ParameterMethod 3: Using s
Parameter in scatterplot()
with Fixed Size
For a uniform marker size for all points, use the s
parameter in scatterplot()
. This approach sets a fixed size for all markers.
Syntax:
sns.scatterplot(x='x_column_name', y='y_column_name', s=fixed_size, data=data_frame)
Example:
Python
import seaborn as sns
import matplotlib.pyplot as plt
data = {
'x': [1, 2, 3, 4, 5],
'y': [10, 15, 12, 17, 20]
}
# Create a scatterplot with fixed marker size
sns.scatterplot(x='x', y='y', s=200, data=data)
plt.show()
Output:
Using s Parameter in scatterplot() with Fixed SizeMethod 4: Using the scatter_kws
Parameter in Seaborn's relplot()
Seaborn's relplot()
provides a high-level interface for drawing scatterplots, and you can pass marker size through the scatter_kws
parameter.
Syntax:
sns.relplot(x='x_column_name', y='y_column_name', size='size_column_name', data=data_frame, scatter_kws={'s': marker_sizes})
Example:
Python
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
data = pd.DataFrame({
'x': [1, 2, 3, 4, 5],
'y': [10, 15, 12, 17, 20],
'size': [100, 200, 300, 400, 500] # Marker size data
})
# Create a relational plot with marker size
sns.relplot(x='x', y='y', data=data, kind='scatter', size='size')
plt.show()
Output:
Using the scatter_kws Parameter in Seaborn's relplot()Customizing Scatterplot Marker Size and Style in Seaborn
1. Changing Marker Style
sns.scatterplot(x="total_bill", y="tip", data=tips_dataset, marker='v')
You can change the marker style by passing a marker style value to the marker
attribute.
2. Setting Context for Larger Plots
sns.set_context('poster')
sns.scatterplot(x="total_bill", y="tip", data=tips_dataset)
This method adjusts the context to make the plot suitable for larger displays like posters.
Conclusion
By using these methods, you can effectively modify the marker size in Seaborn scatterplots to better visualize and interpret your data. Choose the method that best suits your data visualization needs and enhances the clarity of your scatterplots.
Similar Reads
How to Change Label Font Sizes in Seaborn
Seaborn is a powerful Python visualization library that provides a high-level interface for drawing attractive and informative statistical graphics. One of its strong points is customization, allowing you to fine-tune various aspects of your plots, including font sizes of labels, titles, and ticks.
2 min read
How to Adjust Marker Size in Matplotlib?
In this article, we are going to see how to adjust marker size in Matplotlib in Python. We can adjust marker size in plots of matplotlib either by specifying the size of the marker in either plot method or scatter method while plotting the graph. Method 1: Using Plotplot() method used to plot the g
2 min read
Changing Marker Size in Seaborn's lmplot
Seaborn is a powerful data visualization library in Python, built on top of Matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. One of its functions, lmplot, is particularly useful for visualizing linear relationships between variables. However
3 min read
Scatterplot using Seaborn in Python
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 into the data structures from pandas.
4 min read
How to change the size of axis labels in Matplotlib?
Matplotlib is a Python library that helps in visualizing and customizing various plots. One of the customization you can do is to change the size of the axis labels to make reading easier. In this guide, weâll look how to adjust font size of axis labels using Matplotlib. Letâs start with a basic plo
2 min read
How To Align Kde Plot With Strip Plot In Seaborn?
A high-level interface for creating attractive and informative statistical graphics is offered by a powerful python library Seaborn. One of the most common tasks in data visualization is aligning different types of plots in one graph to gain insights into the data. In this article, we will understan
4 min read
Remove White Border from Dots in a Seaborn Scatterplot
Seaborn is a popular data visualization library in Python, built on top of Matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. However, one common issue that users might encounter when creating scatterplots with Seaborn is the appearance of whi
3 min read
How to set axes labels & limits in a Seaborn plot?
In this article, we will learn How to set axes labels & limits in a Seaborn plot. Let's discuss some concepts first. Axis is the region in the plot that contains the data space. The Axes contain two or three-axis(in case of 3D) objects which take care of the data limits.Axes Labels are the label
4 min read
How To Make Counts Appear In Swarm Plot For Seaborn?
Swarm plots, a type of dot plot, effectively visualize data distribution within categories. Unlike standard dot plots, swarm plots avoid overlapping points, making it easier to see individual values. However, including the count of data points in each category can further enhance the plot's clarity.
3 min read
How to change figure size in Plotly in Python
In this article, we will discuss how we can change the figure size in Plotly in Python. Let's firstly take about Plotly in Python. Plotly  Python library provides us with an interactive open-source Plotly library that can support over 40 unique chart types that cover a wide list of statistical, fin
4 min read