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.
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)