Site icon Console Flare Blog

Data Visualization with Seaborn: 7 Steps Guide to Create Scatter Plot

In today’s world, data is more than just numbers—it’s a story waiting to be told. With tools like Python and Seaborn, you can transform raw data into visually appealing and insightful plots that help you make data-driven decisions. This blog walks you through a hands-on example of creating a professional scatter plot using Pandas, Seaborn, and Matplotlib. By the end, you’ll understand how to bring your data to life with a visually stunning and insightful plot.

We will use a dataset called tips.csv, which contains information about restaurant bills, tips, smoking habits, gender, and meal times. The goal is to visualize the relationship between the total bill amount and the tip received, while differentiating the data by customer gender.

Let’s understand the code step by step:

Step 1: Importing the Required Libraries (pandas, matplotlib, and seaborn)

Copy
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
Python
  1. pandas: Helps us read, manipulate, and analyze structured data.
  2. seaborn: A high-level library for creating beautiful and informative visualizations.
  3. matplotlib.pyplot: The foundation for plotting in Python, which Seaborn builds upon.

These libraries work together to give you both the power and flexibility to manipulate and visualize data.

Step 2: Loading the Dataset

Copy
tips_data = pd.read_csv('tips.csv')
print(tips_data)
Python

Here, we load the dataset into a Pandas DataFrame called tips_data using the pd.read_csv() function. The tips.csv file contains restaurant data with columns like:

The print() function outputs the first few rows of the dataset, helping us understand its structure.

Step 3: Setting Up the Plotting Environment

Copy
plt.figure(figsize=(10, 6))
sns.set_theme(style='darkgrid')
sns.set_palette('RdBu')
Python

For more such content and regular updates, follow us on FacebookInstagramLinkedIn

Step 4: Adding a Title

Copy
plt.title('Relation b/w total bill and tip', fontsize=20, color='green')
Python

A well-chosen title sets the context for your audience. Here, we define:

Step 5: Creating the Scatter Plot

Copy
sns.scatterplot(data=tips_data, x='total_bill', y='tip',hue='gender', s=200,alpha=0.7,markers=['*','s'], style='gender')
Python

This is where the graph is created! Let’s break down the arguments:

Step 6: Customizing Axis Labels

Copy
plt.xlabel('Total Bill Amount', fontsize=15, color='red')
plt.ylabel('Tips Received', fontsize=15, color='red')
Python

Descriptive axis labels ensure that viewers can quickly interpret the plot. Here, we define:

Step 7: Displaying the Plot

Copy
plt.show()
Python

Finally, we use the plt.show() function to render the plot. This step brings everything together and displays the beautifully crafted scatter plot.

Interpreting the Plot

The resulting scatter plot reveals:

This simple yet effective visualization provides actionable insights for restaurants or data analysts studying customer behavior.

Why This Visualization Matters

  1. Clarity: The scatter plot clearly shows trends and outliers.
  2. Customization: Using Seaborn and Matplotlib allows you to customize every detail, from colors to markers.
  3. Insights: Adding layers like hue and style enables deeper insights into categorical data.

Read more about DATA SCIENCE

If you’re ready to embark on a rewarding career in data science, consider enrolling in a comprehensive course that focuses on Python.

At ConsoleFlare, we offer tailored courses that provide hands-on experience and in-depth knowledge to help you master Python and excel in your data science journey. Join us and take the first step towards becoming a data science expert with Python at your fingertips.

Register yourself with ConsoleFlare for our free workshop on data science. In this workshop, you will get to know each tool and technology of data analysis from scratch that will make you skillfully eligible for any data science profile.

Thinking, Why Console Flare?

Register yourself  & we will help you switch your career to Data Science in just 6 months.

The Complete code

Copy
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

tips_data=pd.read_csv('tips.csv')
print(tips_data)


plt.figure(figsize=(10,6))
sns.set_theme(style='darkgrid')     # dark,white,whitegrid
sns.set_palette('RdBu')
plt.title('Relation b/w total bill and tip',fontsize=20, color='green')
sns.scatterplot(data=tips_data, x='total_bill',y='tip',hue='gender',s=200,alpha=0.7,markers=['*','s'],style='gender')

plt.xlabel('total bill amount',fontsize=15,color='red')
plt.ylabel('tips received',fontsize=15,color='red')

plt.show()
Python
Exit mobile version