I have a dataframe that looks like this:
In[1]: df.head()
Out[1]:
dataset x y
1 56 45
1 31 67
7 22 85
2 90 45
2 15 42
There are about 4000 more rows. x and y is grouped by the datasets. I am trying to plot a jointplot for each dataset separately using seaborn. This is what I can come up so far:
import seaborn as sns
g = sns.FacetGrid(df, col="dataset", col_wrap=3)
g.map_dataframe(sns.scatterplot, x="x", y="y", color = "#7db4a2")
g.map_dataframe(sns.histplot, x="x", color = "#7db4a2")
g.map_dataframe(sns.histplot, y="y", color = "#7db4a2")
g.add_legend();
but there are all overlapped. How do I make a proper jointplot for each dataset in a subplot? Thank you in advanced and cheers!
You can use
groupbyon your dataset column, then usesns.jointgrid(), and then finally add your scatter plot and KDE plot to the jointgrid.Here is an example using a random seed generator with numpy. I made three "datasets" and random x,y values. See the Seaborn
jointgriddocumentation for ways to customize colors, etc.