Grid of Scatter Plots Based on Meal Time

Using the ‘tips’ dataset, plot a grid of scatter plots with ‘total_bill’ on the x-axis and ‘tip’ on the y-axis, separated by the time of day (Lunch/Dinner).

Example Output:

Utilize sns.FacetGrid along with the map function to generate scatter plots.

import seaborn as sns
import matplotlib.pyplot as plt

def plot_facet_grid():
    tips_data = sns.load_dataset('tips')
    g = sns.FacetGrid(tips_data, col="time")
    g.map(plt.scatter, "total_bill", "tip")
    plt.show()

plot_facet_grid()

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!