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 — Python Boxplot Gallery | Dozens of examples with code

Boxplot

logo of a chart:Box1

A boxplot summarizes the distribution of a numeric variable for one or several groups. It allows to quickly get the median, quartiles and outliers but also hides the dataset individual data points.

In python, boxplots can be made with both seaborn and matplotlib as they both offer a boxplot() function made for the job.

Boxplot sectionAbout this chart

⏱ Quick start

Seaborn is definitely the best library to quickly build a boxplot. It offers a dedicated boxplot() function that roughly works as follows:🔥

Basic boxplot with Python and Seaborn from various data input formats.

Basic boxplot with Python and Seaborn from various data input formats.

# library & dataset
import seaborn as sns
df = sns.load_dataset('iris')

sns.boxplot( x=df["species"], y=df["sepal_length"] )

⚠️ Mind the boxplot

A boxplot is an awesome way to summarize the distribution of a variable. However it hides the real distribution and the sample size. Check the 3 charts below that are based on the exact same dataset.

To read more about this, visit data-to-viz.com that has a dedicated article.

Basic boxplot. You can quickly read the median, quartiles and outliers of each group.

Basic boxplot. You can quickly read the median, quartiles and outliers of each group.

If you add individual points with jitter, a bimodal distribution appears for group B

If you add individual points with jitter, a bimodal distribution appears for group B

If you have a very large dataset, the violin plot is a better alternative than jittering

If you have a very large dataset, the violin plot is a better alternative than jittering

Code and more

⚠️ 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: Boxplots hide information
61
cards

Seaborn logoBoxplots with Seaborn

Seaborn is a python library allowing to make better charts easily. The boxplot function should get you started in minutes. The examples below aim at showcasing the various possibilities this function offers.

Let's start basic. The most simple boxplot, based on 3 differents input formats

Let's start basic. The most simple boxplot, based on 3 differents input formats

Everything you need concerning color customization on your boxplot: transparency, palette in use, manual control..

Everything you need concerning color customization on your boxplot: transparency, palette in use, manual control..

Learn how to highlight a specific group in the dataset to make your point more obvious

Learn how to highlight a specific group in the dataset to make your point more obvious

If you have group and subgroups, you can build a grouped boxplot

If you have group and subgroups, you can build a grouped boxplot

Control the order of groups in the boxplot. It makes the chart more insightful

Control the order of groups in the boxplot. It makes the chart more insightful

To avoid hiding information, you can add individual data points with jitter

To avoid hiding information, you can add individual data points with jitter

Since individual data points are hidden, it is a good practice to show the sample size under each box

Since individual data points are hidden, it is a good practice to show the sample size under each box

Customization: border width

Customization: border width

Customization: use notch

Customization: use notch

Customization: box width

Customization: box width

If you have both groups and subgroups, you'll be interested in a grouped violin plot

If you have both groups and subgroups, you'll be interested in a grouped violin plot

Horizontal boxplot with seaborn

Horizontal boxplot with seaborn

Matplotlib logoBoxplots with Matplotlib

Matplotlib also has a boxplot() function made to build boxplots.

The following tutorials will guide you from its basic usage to the finest customization:

Simple boxplot with matplotlib

Simple boxplot with matplotlib

Flipped, notched and customized boxplot

Flipped, notched and customized boxplot

Grouped boxplot

Grouped boxplot

Beeswarm and boxplot combination

Beeswarm and boxplot combination

Boxplot and ANOVA results on top

Boxplot and ANOVA results on top

Subplot, title, and margin customization

Subplot, title, and margin customization

Add patterns to your boxplot

Add patterns to your boxplot

Matplotlib logoBest python boxplot examples

The web is full of astonishing charts made by awesome bloggers, (often using R). The Python graph gallery tries to display (or translate from R) some of the best creations and explain how their source code works. If you want to display your work here, please drop me a word or even better, submit a Pull Request!

A combination of a violin plot and a boxplot. Allows the comparison of several groups with statistical test results on top.

A combination of a violin plot and a boxplot. Allows the comparison of several groups with statistical test results on top.

Combining boxplot and density chart. A great way to display the distribution of a variable for several groups.

Combining boxplot and density chart. A great way to display the distribution of a variable for several groups.

Related chart types

logo of a chart:Violin

Violin

logo of a chart:Density

Density

logo of a chart:Histogram

Histogram

logo of a chart:Box1

Boxplot

logo of a chart:Joyplot

Ridgeline

logo of a chart:Beeswarm2Big

Beeswarm

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.