Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele PairGrid | Multi-Plot Grids
Deep Dive into the seaborn Visualization

book
PairGrid

PairGrid is a subplot grid for plotting pairwise relationships in a dataset.

This object maps each variable in a dataset onto a column and row in a grid of multiple axes. Different axes-level plotting functions can be used to draw bivariate plots in the upper and lower triangles, and then the marginal distribution of each variable can be shown on the diagonal.

carousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-img
python
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt

df = pd.read_csv('filename.csv')

# Creating the PairGrid variable
g = sns.PairGrid(df)

# Setting diagonale plots
g.map_diag(sns.histplot)

# Setting non-diagonal plots
g.map_offdiag(sns.scatterplot)

plt.show()
Tehtävä

Swipe to start coding

  1. Set the 'ticks' style with the 'lightpink' figure.facecolor.
  2. Create a PairGrid variable using g:
  • Set the data for the g;
  • Set the hue parameter equals the 'species';
  • Set the 'rocket_r' palette.

Set diagonale plots using the .map_diag() function:

  • Create a histplot using the seaborn;
  • Add the kde parameter.

Set non-diagonale plots using the .map_offdiag() function:

  • Create a scatterplot using the seaborn;
  • Set the linewidth parameter equals 0.9;
  • Set the 'purple' edgecolor parameter.

Ratkaisu

import warnings

# Ignore all warnings
warnings.filterwarnings('ignore')


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/penguins_upd.csv')
# Cleaning useless columns
df = df.drop(['Unnamed: 0'], axis=1)

# Set the 'ticks' style with the 'lightpink' facecolor
sns.set_style('ticks', {'figure.facecolor' : 'lightpink'})
# Create a PairGrid variable
g = sns.PairGrid(# Set the data
df,
# Set the hue
hue = 'species',
# Set the palette
palette = 'rocket_r',
# Setting the diag_sharey
diag_sharey = False)
# Set the diagonale plot using the .map_diag() function
g.map_diag(# Create a histplot
sns.histplot,
# Set the kde
kde = True)
# Set non-diagonale plots using the .map_offdiag() function
g.map_offdiag(# Create a scatterplot
sns.scatterplot,
# Set the linewidth
linewidth = 0.9,
# Set the edgecolor

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 5. Luku 2
import warnings

# Ignore all warnings
warnings.filterwarnings('ignore')


# Importing libraries needed
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/66ba0c8e-8422-413c-b7e1-74bd24c61656/penguins_upd.csv')
# Cleaning useless columns
df = df.drop(['Unnamed: 0'], axis=1)

# Set the 'ticks' style with the 'lightpink' facecolor
sns.set_style('___', {'figure.facecolor' : '___'})
# Create a PairGrid variable
g = ___(# Set the data
___,
# Set the hue
___ = 'species',
# Set the palette
___,
# Setting the diag_sharey
diag_sharey = False)
# Set diagonale plots using the .map_diag() function
g.___(# Create a histplot
___,
# Set the kde
kde = ___)
# Set non-diagonale plots using the .map_offdiag() function
g.___(# Create a scatterplot
___,
# Set the linewidth
___ = 0.9,
# Set the edgecolor
___)

# Adding the legend
g.add_legend()
# Displaying the plot
plt.show()

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

We use cookies to make your experience better!
some-alt