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 — Scatter plot with marginal histograms in seaborn

Search for a graph

HOME CORRELATION SCATTER PLOT MARGINAL HISTOGRAMS SEABORN

Scatter plot with marginal histograms in seaborn

Marginal histograms with jointplot

With the jointplot function it is straightforward to create a scatter plot (and other types of plots) with marginal histograms. You will need to input your variables to create the visualization.

import seaborn as sns

df = sns.load_dataset("penguins")

sns.jointplot(data = df,
              x = "bill_length_mm",
              y = "bill_depth_mm")

Scatter plot with marginal histograms in Python with jointgrid

An alternative to the jointplot function is JointGrid, which will provide more flexibility, if needed. jointgrid is just a lightweight wrapper of that function.

import seaborn as sns

df = sns.load_dataset("penguins")

ax = sns.JointGrid(data = df,
                   x = "bill_length_mm",
                   y = "bill_depth_mm")
                   
ax.plot(sns.scatterplot, sns.histplot)

Scatter plot with marginal histograms with JointGrid

Adding a regression line and densities

The function provides an argument named kind that allows you to select between different kinds of plots. Possible options are "scatter" (default), "kde", "hist", "hex", "reg" and "resid".

import seaborn as sns

df = sns.load_dataset("penguins")

sns.jointplot(data = df,
              x = "bill_length_mm",
              y = "bill_depth_mm",
              kind = "reg") # Adds regression and densities

Scatter plot with regression line and marginal histograms with densities in Python

Custom marker

The marker (symbol) used to represent the observations of the scatter plot can be customized with the marker argument.

import seaborn as sns

df = sns.load_dataset("penguins")

sns.jointplot(data = df,
              x = "bill_length_mm",
              y = "bill_depth_mm", 
              marker = "x")

Scatter plot with custom markers and marginal plots in seaborn

Display the axes of the marginal plots

If you want the axes of the marginal plots to be displayed you can set the marginal_ticks argument to True.

import seaborn as sns

df = sns.load_dataset("penguins")

sns.jointplot(data = df,
              x = "bill_length_mm",
              y = "bill_depth_mm", 
              marginal_ticks = True)

Adding the axes to the marginal plots in seaborn

Marginal plots size

By default, the scatter plot is 5 times bigger than the marginal plots. You can change the aspect ratio with ratio. Note that this argument only allows integers as input.

import seaborn as sns

df = sns.load_dataset("penguins")

# Scatter plot two times bigger than the histograms
sns.jointplot(data = df,
              x = "bill_length_mm",
              y = "bill_depth_mm", 
              ratio = 2) 

Change the aspect ratio of the plot and the marginal plots in Python

Color customization

Color customization of a joint plot in seaborn

Finally, you can also customize the colors. If you only provide a color using the color argument both the histograms and the scatter plot will have the same color.

import seaborn as sns

df = sns.load_dataset("penguins")

sns.jointplot(data = df,
              x = "bill_length_mm",
              y = "bill_depth_mm",
              color = "lavender")

Change the color of the marginal histograms in seaborn

However, if you prefer a different color for the histograms you can pass a dictionary to the marginal_kws argument and select the desired color. Note that this argument can also be used to customize other arguments related to the histograms.

import seaborn as sns

df = sns.load_dataset("penguins")

sns.jointplot(data = df,
              x = "bill_length_mm",
              y = "bill_depth_mm",
              color = "dimgray",
              marginal_kws = dict(color = "lavender"))
R CODER website
Storytelling with Data

Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon
Data Sketches

Data Sketches

A journey of imagination, exploration, and beautiful data visualizations

Buy on Amazon

See also

Hexbin chart in matplotlib

Hexbin chart in matplotlib

3D surface plot in matplotlib

3D surface plot in matplotlib

Scatter plot with regression line in seaborn

Scatter plot with regression line in seaborn

Scatter plot in pandas

Scatter plot in pandas

Bubble chart in matplotlib

Bubble chart in matplotlib

Scatter plot in seaborn

Scatter plot in seaborn

2D histogram in matplotlib

2D histogram in matplotlib

Scatter plot in plotly

Scatter plot in plotly

Bubble chart in plotly

Bubble chart in plotly

Heatmaps in plotly with imshow

Heatmaps in plotly with imshow

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.