• 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 Add Outline/Edge Color to Histogram in Seaborn?

datavizpyr · January 7, 2020 ·

In this tutorial, we will see an example of adding edge color/edge line to histograms made with Seaborn.

Let us load the packages needed to make histogram with outlines using Seaborn.

 
import seaborn as sns 
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

We will use Seattle weather data from vega_datasets to make histograms.

 
from vega_datasets import data
seattle_weather = data.seattle_weather()
print(seattle_weather.head(n=3))

Let us first make a histogram with Seaborn’s distplot.

 
sns.distplot(seattle_weather['temp_max'])
plt.title('Seattle Weather Data', fontsize=18)
plt.xlabel('temp_max', fontsize=16)
plt.ylabel('Density', fontsize=16)

By default, distplot() fills the bars in histogram with blue color. However, it does not have any outline to the edges of the bar. And thus makes the histogram bars look continuous.

Basic Histogram without edge line: Seaborn
Basic Histogram without edge color: Seaborn

We can add outline or edge line with colors using hist_kws as argument to distplot() function. We should specify hist_kws as dictionary with properties for it. For example, in our example we specify the edgecolor and linewidth.

 
sns.distplot(seattle_weather['temp_max'],
             hist_kws=dict(edgecolor="black", linewidth=2))
plt.title('Seattle Weather Data', fontsize=18)
plt.xlabel('temp_max', fontsize=16)
plt.ylabel('Density', fontsize=16)
Add Edge Color to Histogram with Seaborn
Histogram with edge line: Seaborn

Related posts:

Change Histogram ColorHistograms with Seaborn in Python Grouped Barplot with SeabornHow To Make Grouped Barplots in Python with Seaborn? How To Manually Order Boxplot with Seaborn?How To Manually Order Boxplot in Seaborn? Grouped Boxplot with Jittered Data Points SeabornGrouped Boxplot with Jittered Points with Seaborn Python

Filed Under: Histogram with Edge Color Seaborn, Python Tagged With: Histogram, 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