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.






python9912345678910111213141516import pandas as pdimport seaborn as snsfrom matplotlib import pyplot as pltdf = pd.read_csv('filename.csv')# Creating the PairGrid variableg = sns.PairGrid(df)# Setting diagonale plotsg.map_diag(sns.histplot)# Setting non-diagonal plotsg.map_offdiag(sns.scatterplot)plt.show()
Tehtävä
Swipe to start coding
- Set the
'ticks'
style with the'lightpink'
figure.facecolor
. - Create a
PairGrid
variable usingg
:
- 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 theseaborn
; - Add the
kde
parameter.
Set non-diagonale plots using the .map_offdiag()
function:
- Create a
scatterplot
using theseaborn
; - Set the
linewidth
parameter equals0.9
; - Set the
'purple'
edgecolor
parameter.
Ratkaisu
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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ää?
Kiitos palautteestasi!
Osio 5. Luku 2
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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ä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme