Catplot
Note
catplot
=FacetGrid
+stripplot
/swarmplot
/boxplot
/violinplot
/barplot
/pointplot
The catplot
function provides a new framework giving access to several types of plots that show a relationship between a numerical variable and one or more categorical variables, like boxplot
, stripplot
and so on.









Note
Scroll down to see the full plot when you cope with the task!
Oppgave
Swipe to start coding
- Set the
'white'
style with the'aliceblue'
axes.facecolor
. - Create the
catplot
using theseaborn
library:
- Set the
x
parameter equals the'species'
; - Set the
y
parameter equals the'body_mass_g'
; - Set the
hue
parameter equals the'sex'
; - Set the
row
parameter equals the'island'
; - Set the
'viridis'
palette
; - Set the
alpha
parameter equals0.6
; - Disable the
legend_out
.
Løsning
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
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.csv')
# Set the 'white' style with the 'aliceblue' facecolor
sns.set_style('white', {'axes.facecolor' : 'aliceblue'})
# Create a catplot
sns.catplot(# Set the x
x = 'species',
# Set the y
y = 'body_mass_g',
# Set the hue
hue = 'sex',
# Set the row
row = 'island',
# Set the palette
palette = 'viridis',
# Set the alpha
alpha = 0.6,
# Set the legend_out
legend_out = False,
# Setting the data
data = df)
# Displaying the plot
plt.show()
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 8
single
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
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.csv')
# Set the 'white' style with the 'aliceblue' facecolor
___(___, {'___.facecolor' : '___'})
# Create a catplot
___(# Set the x
___,
# Set the y
y = '___',
# Set the hue
___,
# Set the row
___ = '___',
# Set the palette
___,
# Set the alpha
___,
# Set the legend_out
legend_out = ___,
# Setting the data
data = df)
# Displaying the plot
plt.show()
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår