I'm an Artist, that's how I See it!
We mentioned that the seaborn
is based on the matplotlib
. That is why all seaborn
styles are set using matplotlib
functions.
We can use the axes_style()
function with no arguments to see which functions are used for the current style.
And then, we have the opportunity to adjust the desired parameters manually and create our unique style!
To change individual style settings manually:
python91234import seaborn as sns# Setting the unique stylesns.set_style('style_name', {'axes.facecolor': 'red', 'grid.color': 'black',...})
Try this code to look at the customized plot:
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
# Generate random data for the line plot
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Set the style of the plot using sns.set_style()
sns.set_style('whitegrid', {'axes.facecolor': 'lightgrey', 'grid.color': 'white', 'grid.linewidth': 1})
# Create the line plot using sns.lineplot()
sns.lineplot(x = x, y = y, color = 'blue')
# Add a title and axis labels to the plot
plt.title('Lineplot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
# Display the plot
plt.show()
123456789101112131415161718192021import seaborn as sns import numpy as np import matplotlib.pyplot as plt # Generate random data for the line plot x = np.linspace(0, 10, 100) y = np.sin(x) # Set the style of the plot using sns.set_style() sns.set_style('whitegrid', {'axes.facecolor': 'lightgrey', 'grid.color': 'white', 'grid.linewidth': 1}) # Create the line plot using sns.lineplot() sns.lineplot(x = x, y = y, color = 'blue') # Add a title and axis labels to the plot plt.title('Lineplot') plt.xlabel('X-axis') plt.ylabel('Y-axis') # Display the plot plt.show()
Compito
Swipe to start coding
- Import
seaborn
withsns
alias. - Import
matplotlib.pyplot
withplt
alias. - Import
pandas
withpd
alias. - Set
'whitegrid'
style with'xtick.color' - white
,'ytick.color' - white
,'figure.facecolor' - grey
,'font.family'- ['monospace']
. - Rotate labels along the Ox axis by 45 degrees.
- Show the plot.
Soluzione
99
1
2
3
4
5
6
7
8
9
10
11
12
13
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', {'xtick.color':'white', 'ytick.color':'white', 'figure.facecolor':'grey', 'font.family':['monospace']})
sns.countplot(x = 'Bamboo', data = df)
plt.xticks(rotation = 45)
plt.show()
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 5
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Import 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 unique style
sns.set_style('___', {'___' : '___', '___' : '___', '___' : '___', 'font.family' : ['___']})
# Creating the countplot
sns.countplot(x = 'Bamboo', data = df)
# Rotate
plt.___(___)
# 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