Matplotlib/Seaborn double scatter plot with three side histograms (extending JointGrid)

1.7k views Asked by At

I have three datasets (data1, data2, data3), and I'd like to create a rather complicated plot: a stacked scatter plot (two scatter plots that on top of each other) with three histograms on sides.

This is what I have so far for one set, and below you can see the resulting plot:

from numpy.random import randn
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

data1 = randn(500)
data2 = randn(500) * 20
data3 = randn(500) + 5

e1c = sns.color_palette()[0]
e2c = sns.color_palette()[1]
e3c = sns.color_palette()[2]

with sns.axes_style("white"):
    g = sns.JointGrid(data2, data3)
    g.plot_marginals(sns.distplot, kde=False, color=e3c)
    g.plot_joint(plt.scatter, color=e3c, alpha=.2)

    plt.show()

resulting plot

And now the same one with the annotations what I exactly need to produce:

Annotated

To make it more complicated, the left and right y axes (data1 and data 3) have a different range of values.

So to summarise, here are the list of things I need to include:

  1. Another scatter plot (data2, data1) in color e1c
  2. data1 has to have a histogram on the left, in color e1c
  3. All histograms should have finer bins (say, 5x more bins).
  4. Histogram on top (data2) should be in color e2c.
  5. There should be two y axis (one for data1, another for data3).
  6. There should be labels on each axis ("Data 1", ...).

How to accomplish this?

0

There are 0 answers