Swarmplot
The swarmplot
is similar to stripplot
. Only the points are adjusted so they won't overlap, as it helps to represent the distribution of values better.











Uppgift
Swipe to start coding
- Set the
'whitegrid'
style with the'seashell'
axes.facecolor
. - Create the
swarmplot
using theseaborn
library:
x
parameter equals the'day'
;- Set the
y
parameter equals the'total_bill'
; - Set the
hue
parameter equals the'sex'
; - Set the
linewidth
parameter equals1
; - Set the
size
parameter equals2
; - Set the
dodge
parameter equals theTrue
; - Set the
'rocket'
palette.
Lösning
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/tips.csv')
# Set the 'whitegrid' style with the 'seashell' facecolor
sns.set_style('whitegrid', {'axes.facecolor': 'seashell'})
# Create a swarmplot
sns.swarmplot(# Set the x
x = 'day',
# Set the y
y = 'total_bill',
# Set the hue
hue = 'sex',
# Set the linewidth
linewidth = 1,
# Set the size
size = 2,
# Set the dodge
dodge = True,
# Set the palette
palette = 'rocket',
# Setting the data
data = df)
# Displaying the plot
plt.show()
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 2
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/tips.csv')
# Set the 'whitegrid' style with the 'seashell' facecolor
___('___', {___})
# Create a swarmplot
___(# Set the x
___,
# Set the y
___,
# Set the hue
___,
# Set the linewidth
___,
# Set the size
___ = 2,
# Set the dodge
dodge = ___,
# Set the palette
palette = '___',
# Setting the data
data = df)
# Displaying the plot
plt.show()