Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Swarmplot | Categorical Plot Types
Deep Dive into the seaborn Visualization

book
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.

carousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-img
Uppgift

Swipe to start coding

  1. Set the 'whitegrid' style with the 'seashell' axes.facecolor.
  2. Create the swarmplot using the seaborn 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 equals 1;
  • Set the size parameter equals 2;
  • Set the dodge parameter equals the True;
  • 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?

Hur kan vi förbättra det?

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()
toggle bottom row
some-alt