Final Challenge
Opgave
Swipe to start coding
This is the right time for the final task of drawing a plot based on the material we have learned in this course. After completing this task, you will definitely be ready to create cool and colorful graphics for your future projects 🥳.
-
Import the
seaborn
withsns
alias. -
Import the
matplotlib.pyplot
withplt
alias. -
Import the
pandas
withpd
alias. -
Read the file.
-
Set
blue
color forboy
,pink
forgirl
values. -
Set a
histplot
variable with histplot'sbinwidth = 0.1
,data = df
. -
Set the title
'Yummy fish!'
. -
Set the xlabel
'Kilos of fish'
. -
Set the context
paper
. -
Set the unique style:
'axes.facecolor' - 'white'
,'figure.facecolor' - 'black'
,'axes.labelcolor' - 'white'
,'xtick.color':'white'
,'ytick.color':'white'
. -
Show the plot.
Løsning
99
1
2
3
4
5
6
7
8
9
10
11
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/final_chlldg.csv')
colors = {'boy':'blue', 'girl':'pink'}
g = sns.histplot(x = 'kilos', hue = 'gender', palette = colors, data = df, binwidth = 0.1)
g.set_title('Yummy fish!', color = 'white')
g.set(xlabel = 'Kilos of fish')
sns.set_context('paper')
sns.set_style('darkgrid', {'axes.facecolor':'white', 'figure.facecolor':'black', 'axes.labelcolor':'white', 'xtick.color':'white', 'ytick.color':'white'})
plt.show()
Var alt klart?
Tak for dine kommentarer!
Sektion 3. Kapitel 6
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
# Import libraries needed
___
___
___
# Read the file
df = ___('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/final_chlldg.csv')
# Set colors for the hue
colors = {'___ ':'___', '___': '___'}
# Set plot value and binwidth
g = ___(x = 'kilos', hue = 'gender', palette = ___, ___ = ___, ___ = 0.1)
# Set the title
___.___('___', color = 'white')
# Set name to xlabel
___.___(___)
# Set the context
___.___('paper')
# Set the unique style
___('darkgrid', {'axes.facecolor':'white', '___':'black', 'axes.___':'white', 'xtick.___':'___', 'ytick.color':'___'})
# Show the plot
___
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat