• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How To Change Edge Color on Seaborn Scatter Plot?

datavizpyr · January 31, 2021 ·

Seaborn’s scatterplot function allows us to make compelling scatter plots easily. In this post we will learn how to customize edge color of a scatter plot made with Seaborn. By default, Seaborn’s scatter plot function colors the markers edge color to be white.

In this post, we will see how to change the default edge color. First, we will see how to remove the white edge color and then see how to color the edge with a specific color of interest. And then we will also see how to change the thickness of the edge color line. Finally, we will learn how to use kwargs (key word arguments) to pass multiple arguments to customize Seaborn plot.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
penguins_data="https://raw.githubusercontent.com/datavizpyr/data/master/palmer_penguin_species.tsv"
# load penguns data with Pandas read_csv
df = pd.read_csv(penguins_data, sep="\t")
df.head()

Seaborn’s scatterplot with default white edgecolor

Let us make a scatter plot with Seaborn’s scatterplot function. Here we color the points by a variable and also use another variable to change the size of the markers or points.

By default, Seaborn’s scatterplot colors the outer line or edge of the data points in white color.

sns.set_context("talk", font_scale=1)
plt.figure(figsize=(10,8))
sns.scatterplot(x="flipper_length_mm",
                y="culmen_length_mm",
                data=df,
                size="body_mass_g",
                sizes=(40,100),
                hue = 'species')
plt.xlabel("Flipper Length (mm)",fontweight ='bold', size=14)
plt.ylabel("Culmen Length (mm)", fontweight ='bold',size=14)
plt.savefig("Scatterplot_seaborn.png",
            format='png',dpi=150)
Seaborn Scatterplot with default white edgecolor
Seaborn Scatterplot with default white edgecolor

How to Remove default white edgecolor in Seaborn’s scatterplot?

We can change the default white color of edge markers or data points using argument “edgecolor”. When we specify, edgecolor=”none”, we remove edge color. Note that the value of argument is “none” not “None”.

sns.scatterplot(x="flipper_length_mm",
                y="culmen_length_mm",
                data=df,
                size="body_mass_g",
                sizes=(40,100),
                hue = 'species',
                edgecolor="none")
plt.xlabel("Flipper Length (mm)",fontweight ='bold', size=14)
plt.ylabel("Culmen Length (mm)", fontweight ='bold',size=14)
plt.savefig("Scatterplot_seaborn_no_edgecolor.png",
            format='png',dpi=150)
Scatterplot Seaborn with no edgecolor
Scatterplot Seaborn with no edgecolor

How to Change edgecolor in Seaborn’s scatterplot?

We can change the color of edge by specifying a color to “edgecolor” argument. In this example, below we set the edge color of markers or points to black with edgecolor=”black”.

plt.figure(figsize=(10,8))
sns.scatterplot(x="flipper_length_mm",
                y="culmen_length_mm",
                data=df,
                size="body_mass_g",
                sizes=(40,100),
                hue = 'species',
                edgecolor="black")
plt.xlabel("Flipper Length (mm)",fontweight ='bold', size=14)
plt.ylabel("Culmen Length (mm)", fontweight ='bold',size=14)
plt.savefig("Scatterplot_seaborn_black_edgecolor.png",
            format='png',dpi=150)
Seaborn Scatterplot with black edgecolor
Seaborn Scatterplot with black edgecolor

How to Change edge color and its line width in Seaborn’s scatterplot?

We can also change the thickness of edge color using linewidth argument. Here, we set the edge color to black and specify line width using linewidth argument.

plt.figure(figsize=(10,8))
sns.scatterplot(x="flipper_length_mm",
                y="culmen_length_mm",
                data=df,
                size="body_mass_g",
                sizes=(40,100),
                hue = 'species',
                edgecolor="black",
                linewidth=2)
plt.xlabel("Flipper Length (mm)",fontweight ='bold', size=14)
plt.ylabel("Culmen Length (mm)", fontweight ='bold',size=14)
plt.savefig("Scatterplot_seaborn_edgecolor_linewidth.png",
            format='png',dpi=150)
Seaborn Scatterplot: Change edgecolor and line width
Seaborn Scatterplot: Change edgecolor and line width

How to Change edge color and its line width in Seaborn’s scatterplot with kwargs?

Another way to customize edge color and line width using Python’s kwargs. Here we specify the edge color and linewidth as a dictionary and provide the kwargs to Seaborn’s scatterplot.

plt.figure(figsize=(10,8))
kwargs  =   {'edgecolor':"black", # for edge color
             'linewidth':1, # line width of spot
            }
sns.scatterplot(x="flipper_length_mm",
                y="culmen_length_mm",
                data=df,
                size="body_mass_g",
                sizes=(40,100),
                hue = 'species',
                **kwargs)
plt.xlabel("Flipper Length (mm)",fontweight ='bold', size=14)
plt.ylabel("Culmen Length (mm)", fontweight ='bold',size=14)
plt.savefig("Scatterplot_seaborn_edgecolor_with_kwargs.png",
            format='png',dpi=150)
Seaborn Scatterplot: Change edgecolor with kwargs
Seaborn Scatterplot: Change edgecolor with kwargs

Related posts:

Grouped Barplot with SeabornHow To Make Grouped Barplots in Python with Seaborn? Color and Shape by variables: Seaborn scatterplot()How To Make Scatter Plots with Seaborn scatterplot in Python? Grouped Boxplot with Jittered Data Points SeabornGrouped Boxplot with Jittered Points with Seaborn Python Customize Facetgrid plot titles in Seaborn_PythonHow to Customize Titles in Multi-Panel plots with Seaborn?

Filed Under: Python, Scatterplot change edgecolor, Seaborn, Seaborn Scatterplot Tagged With: Python, Seaborn

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version