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

  • All
  • Best
  • Libs
  • Learn

This view

  • Original page
  • New address

GeezerVison is showing python-graph-gallery.com — 2d density chart

2D Density Chart

logo of a chart:2dDensity

This section explains how to build a 2d density chart or a 2d histogram with python. Those chart types allow to visualize the combined distribution of two quantitative variables. They can be built with Matplotlib or Seaborn.

2D Density sectionAbout this chart

💡 What is a 2D density chart?

There are several chart types allowing to visualize the distribution of a combination of 2 numeric variables. They always have a variable represented on the X axis, the other on the Y axis, like for a scatterplot (left).

Then the number of observations within a particular area of the 2D space is counted and represented with a color gradient. The shape can vary: hexagones result in a hexbin chart, squares in a 2d histogram. A kernel density estimate can be used to get a 2d density plots or a contour plots

Cheat sheet: line customization with matplotlib

Cheat sheet: line customization with matplotlib

Confusing? Visit data-to-viz to clarify..

More viz explanationShow me the code

Seaborn logoContour plot with Seaborn

The contour plot can be easily built thanks to the kdeplot() function of the Seaborn library.

Basic contourplot with seaborn.

Basic contourplot with seaborn.

Basic contourplot with seaborn.

Basic contourplot with seaborn.

Basic contourplot with seaborn.

Basic contourplot with seaborn.

Matplotlib logo2D histogram with Matplotlib

Build a 2d histogram thanks to the hist2d() function of the Matplotlib library. Do not forget to play with the bins argument to find the value representing the best your data.

Basic 2D histogram with bins customization

Basic 2D histogram with bins customization

Control the color in the 2d histogram.

Control the color in the 2d histogram.

Black and white, color scale legend.

Black and white, color scale legend.

⚠️ Avoid the 61 most common dataviz mistakes

Boxplots hiding information, pie charts, cut axes, spaghetti charts... I gathered the 61 dataviz caveats I see the most as a deck of cards. Each card shows a chart that is not ideal, and a better alternative.

Get the full deck for free:

I respect your privacy. Unsubscribe anytime.

Dataviz caveat card: Beware of overplotting
61
cards

Matplotlib logoHexbin chart with Matplotlib

Split the graph area in hexagones and you get a hexbin density chart. This time, it is matplotlib that gets you covered thanks to its hexbin() function.

Basic hexbin with bins customization

Basic hexbin with bins customization

Control the color in the hexbin.

Control the color in the hexbin.

Black and white, color scale legend.

Black and white, color scale legend.

Matplotlib logo2d density chart with Matplotlib

2D densities are computed thanks to the gaussian_kde() function and plotted thanks with the pcolormesh() function of matplotlib().

Basic 2d density with bins customization

Basic 2d density with bins customization

Control the color in the 2d density.

Control the color in the 2d density.

Black and white, color scale legend.

Black and white, color scale legend.

Matplotlib logo2d density and marginal plots

2D densities often combined with marginal distributions. It helps to highlight the distribution of both variables individually. It is pretty straightforward to add thanks to the jointplot() function of the Seaborn library.

Marginal distribution and hexbin.

Marginal distribution and hexbin.

Marginal distribution and contour.

Marginal distribution and contour.

General customization.

General customization.

Related chart types

logo of a chart:ScatterPlot

Scatterplot

logo of a chart:Heatmap

Heatmap

logo of a chart:Correlogram

Correlogram

logo of a chart:BubblePlot

Bubble

logo of a chart:ScatterConnected

Connected Scatter

logo of a chart:2dDensity

2D Density

300 projects

💡 Out of dataviz inspiration?

I have spent years collecting the most beautiful data visualizations out there. Get the list of my top 300 dataviz projects, hand-picked, for free.

I respect your privacy. Unsubscribe anytime.

You are visitor 01402503 — 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.