GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Histogram with density in seaborn

Search for a graph

HOME DISTRIBUTION HISTOGRAM DENSITY SEABORN

Histogram with density in seaborn

Histogram with kernel density estimation

Setting the kde argument of the histplot function to True will add a curve representing the kernel density estimate of the data, calculated with the default parameters of the kdeplot function.

import numpy as np
import seaborn as sns

# Data simulation
rng = np.random.RandomState(1)
x = rng.normal(0, 1, size = 1000)
df = {'x': x}

# Histogram
sns.distplot(x = x, kde = True)

# Equivalent to:
sns.distplot(x = "x", kde = True, data = df)

Histogram in seaborn with density line

Kernel density estimate computation

Note that you can pass additional arguments to the kdeplot function with kde_kws. This will allow you to override the default arguments for the computation, such as the bandwidth used.

import numpy as np
import seaborn as sns

# Data simulation
rng = np.random.RandomState(1)
x = rng.normal(0, 1, size = 1000)
df = {'x': x}

# Histogram
sns.histplot(x = x, kde = True,
             kde_kws = {'bw_adjust': 0.5})

Change the bandwidth of the kernel density estimate in Python

Curve styling

The line_kws argument of the function can be used to customize the style of the kernel density estimate line passing a dictionary with the desired values. Note that you can override the default color of the line with set_color, as shown below.

Change the color of the density line of a histogram made in seaborn with histplot

import numpy as np
import seaborn as sns

# Data simulation
rng = np.random.RandomState(1)
x = rng.normal(0, 1, size = 1000)
df = {'x': x}

# Histogram
sns.histplot(x = x, kde = True,
             line_kws = {'linestyle':'dashed',
                         'linewidth':'2'}).lines[0].set_color('red')
R CODER website
Fundamentals of Data Visualization

Fundamentals of Data Visualization

A Primer on Making Informative and Compelling Figures

Buy on Amazon
Better Data Visualizations

Better Data Visualizations

A Guide for Scholars, Researchers, and Wonks

Buy on Amazon
Storytelling with Data

Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon

See also

Swarm plot in seaborn

Swarm plot in seaborn

Violin plot in seaborn

Violin plot in seaborn

Violin plot in matplotlib

Violin plot in matplotlib

Ridgeline plots (joy plots) in matplotlib with joypy

Ridgeline plots (joy plots) in matplotlib with joypy

Box plot in plotly

Box plot in plotly

Box plot in pandas

Box plot in pandas

Box plot in matplotlib

Box plot in matplotlib

Strip plot in seaborn

Strip plot in seaborn

Histogram in pandas

Histogram in pandas

Kernel density plot in seaborn with kdeplot

Kernel density plot in seaborn with kdeplot

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.