Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating plot matrix with relplot in seaborn

I am trying to add multiple plots and create a matrix plot with seaborn. unfortunately python give me following warning.

"relplot is a figure-level function and does not accept target axes. You may wish to try scatterplot"

fig, axes = plt.subplots(nrows=5,ncols=5,figsize=(20,20),sharex=True, sharey=True)

for i in range(5):
    for j in range(5):
        axes[i][j]=seaborn.relplot(x=col[i+2],y=col[j+2],data=df,ax=axes=[i][j])

I would like to know if there's any method with which I can combine all the plots plotted with relplot.

like image 632
kinto numa Avatar asked Aug 11 '26 02:08

kinto numa


1 Answers

relplot works differently than for example scatterplot. With relplot you don't need to define subplots and loop over them. Instead you can say what you would like to vary on each row or column of a graph.

For an example from the documentation:

import seaborn as sns
sns.set(style="ticks")
tips = sns.load_dataset("tips")
g = sns.relplot(
    x="total_bill", y="tip", hue="day",
    col="time", row="sex", data=tips
)

Which says: on each subplot, plot the total bill on the x-axis, the tip on the y-axis and vary the hue in a subplot with the day. Then for each column, plot unique data from the "time" column of the tips dataset. In this case there are two unique times: "Lunch" and "Diner". And finally vary the "sex" for each subplot row. In this case there are two types of "sex": "Male" and "Female", so on one row you plot the male tipping behavior and on the second the female tipping behavior.

enter image description here

I'm not sure what your data looks like, but hopefully this explanation helps you.

like image 190
Roald Avatar answered Aug 13 '26 15:08

Roald



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!