Adding the Plot Title
Plotting in the seaborn
can be used to create 2 types of plots: FacetGrids and AxesSubplots.
We have learned only plots of the AxesSubplots type, so we will learn how to customize only plots of the corresponding type.
To add the title you need to:
Declare a plot variable;
Add the title.
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Importing libraries needed
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/example3.csv')
# Creating the countplot and declaring the variable
g = sns.countplot(x = 'food', data = df)
# Setting the title
g.set_title('Food')
# Showing the plot
plt.show()
12345678910111213141516# Importing libraries needed import seaborn as sns import matplotlib.pyplot as plt import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/example3.csv') # Creating the countplot and declaring the variable g = sns.countplot(x = 'food', data = df) # Setting the title g.set_title('Food') # Showing the plot plt.show()
Compito
Swipe to start coding
- Import the
seaborn
withsns
alias. - Import the
matplotlib.pyplot
withplt
alias. - Import the
pandas
withpd
alias. - Read the file using
df
variable. - Create a histplot variable
g
. - Set the title
'Fish'
. - Show the plot.
Soluzione
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/fish.csv')
g = sns.histplot(x = 'answer', data = df, binwidth = 0.2)
g.set_title('Fish')
plt.show()
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 2
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Import libraries needed
___
___
___
# Read the file and set the plot variable
___ = ___('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/fish.csv')
# Create the histplot
___.___(x = 'answer', data = df, binwidth = 0.2)
# Set a title
___.___('___')
# Show the plot
___
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione