Decoration and...Decoration!
Setting the style for the plot
To set the style use:
pythonsns.set_style('style_name')
Styles available: white
, dark
, whitegrid
, darkgrid
, ticks
etc.
Changing colors of the main elements of the plot
seaborn
has different palette options.
Below there are a few of them.
Palettes: RdBu
, PRGn
, RdBu_r
, PRGn_r
(different colors in the palette), Greys
, Blues
, PuRd
, GnBu
(gradient colors).
You can also create your unique palette by creating a list variable. To set the palette use:
pythonsns.set_palette(palette_name)
Context setting
To set the context use:
pythonsns.set_context('context_name')
Contexts available: paper
, notebook
, talk
, poster
etc.
Tâche
Swipe to start coding
- Import
seaborn
withsns
alias. - Import
matplotlib.pyplot
withplt
alias. - Import
pandas
withpd
alias. - Set the
'whitegrid'
style. - Set the
'paper'
context. - Rotate labels along the Ox axis by 45 degrees.
Solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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/bamboo.csv')
sns.set_style('whitegrid')
sns.set_context('paper')
sns.countplot(x = 'Bamboo', data = df)
plt.xticks(rotation = 45)
plt.show()
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 4
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Importing libraries needed
___
___
___
# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/bamboo.csv')
# Set the style
___.___('___')
# Set the scale
___
# Creating the countplot
sns.countplot(x = 'Bamboo', data = df)
# Rotate
plt.___(___)
# Showing the plot
plt.show()
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion