Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Rugplot | Distributions of Data
Deep Dive into the seaborn Visualization

book
Rugplot

The rugplot is intended to complement other plots by showing the location of individual observations in an unobtrusive way.

carousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-imgcarousel-img
Task

Swipe to start coding

  1. Set the 'darkgrid' style with the disabled 'axes.grid' and the 'axes.facecolor' equals the 'aliceblue' (color). We learned how to do that in the first part of the course.
  2. Create the kdeplot using the seaborn library.
  3. Create the rugplot using the seaborn library:
  • Set the x parameter equals the 'total_bill';
  • Set the hue parameter equals the 'sex';
  • Set the height parameter equals 0.05;
  • Set the 'magma' palette;
  • Set the data using the df;
  • Display the plot.

Solution

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 'darkgrid' style
sns.set_style('darkgrid',
# Disable the axes.grid
{'axes.grid' : False,
# Set the 'aliceblue' facecolor
'axes.facecolor' : 'aliceblue'})
# Create a kdeplot
sns.kdeplot(x = 'total_bill',
hue = 'sex',
palette = 'magma',
multiple = 'layer',
fill = True,
data = df)

# Create a rugplot
sns.rugplot(# Set the x
x = 'total_bill',
# Set the hue
hue = 'sex',
# Set the height
height = 0.05,
# Set the palette
palette = 'magma',

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 3
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 'darkgrid' style
sns.set_style('___',
# Disable the axes.grid
{'axes.___ ' : ___,
# Set the 'aliceblue' facecolor
'___.facecolor' : '___'})
# Create a kdeplot
sns.___(x = 'total_bill',
hue = 'sex',
palette = 'magma',
multiple = 'layer',
fill = True,
data = df)

# Create a rugplot
sns.___(# Set the x
___,
# Set the hue
___,
# Set the height
height = ___,
# Set the palette
___,

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt