top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

Data Visualization Using Python: 6 Essential Chart Types And Their Best Use Cases

Updated: May 9




Visual storytelling in data analysis is the practice of using visuals—charts, graphs, plots, and annotated figures—to communicate insights from data in a compelling and intuitive way. When using Python, which offers powerful libraries like Matplotlib, Seaborn, Plotly, visual storytelling becomes a core component of effective data communication.


🧠 Why Visual Storytelling Matters in Data Analysis

Reason

Description

Simplifies complexity


Python visuals help distill large datasets and complex models into understandable visuals (e.g., line plots).

Engages audience

A well-designed graph tells a story more clearly than raw numbers or tables, keeping your audience focused and interested.

Reveals patterns and outliers

Visuals make trends, anomalies, and correlations visible quickly (e.g., scatter plots for regression analysis).

Aids decision-making

Business stakeholders can make informed decisions faster when data insights are visually clear.

Bridges gaps between technical and non-technical teams


Storytelling with visuals makes it easier to communicate insights across roles and expertise levels.


🛠 Python Libraries for Visual Storytelling:

Library

Best Used For

Example Use Case

Matplotlib

Custom plots and static images

Creating time series or bar charts with annotations.

Seaborn

Statistical visualizations

Visualizing correlation or distribution plots

Plotly

Interactive visualizations, Hierarchical Data

Dashboards or web apps for exploring data dynamically,Visualize nested categories using sunburst charts

In this blog, we’ll walk through 6 essential charts every data analyst should know, with Python examples using the visualization libraries - Matplotlib, Seaborn and Plotly. These charts cover a wide range of use cases — from trends to comparisons, distributions to correlations.


  1. 📈 Line Chart – For Trends Over Time


A line chart connects data points with straight lines, making it ideal for showing changes or trends over time.

When to use:  You want to show how something changes over time — like stock prices, website visits, or monthly sales.


# Import the plotting library
import matplotlib.pyplot as plt 

# Define data
x = [1, 2, 3, 4, 5]  # Example: Time in months
y = [10, 20, 15, 25, 30]  # Example: Sales in thousands

# Create the plot
plt.plot(x, y, marker='o', linestyle='-', color='blue')

# Add labels and title
plt.xlabel('Month')
plt.ylabel('Sales ($1000)')
plt.title('Monthly Sales Trend')

# Show the chart
plt.show()

2. 📊 Bar Chart – For Category Comparisons


Bar charts are perfect for comparing quantities across different categories.

When to use: You’re comparing discrete groups, such as revenue by region or customers by subscription type.


# Import the plotting library
import matplotlib.pyplot as plt 

# Define data
products = ['MacBook', 'iPad', 'AirPods']
sales = [300, 450, 250]

# Create the plot
plt.bar(products, sales, color='skyblue')

# Add labels and title
plt.title('Sales by Product')
plt.xlabel('Product')
plt.ylabel('Sales')

# Show the chart
plt.show()


3. 🥧 Pie Chart – For Part-to-Whole Analysis


Pie charts show proportions and are best when illustrating how a whole is divided into parts.

When to use: You need to show proportions — like how a budget is divided among departments.

# Import the plotting library
import matplotlib.pyplot as plt 

# Define data
bmi_levels = ['Underweight', 'Normal', 'Overweight', 'Obese']
sizes = [10, 45, 25, 20]

# Create the plot
plt.pie(sizes, labels=bmi_levels, autopct='%1.1f%%', startangle=90)

# Add labels and title
plt.title('BMI Classification')
plt.axis('equal')  

# Show the chart
plt.show()

4. 📊 Histogram – For Distribution Insight


Histograms are used to visualize the distribution of numerical data by grouping values into bins.

When to use: You’re exploring how values are spread, like age distribution or transaction amounts.


# Import the plotting library
import matplotlib.pyplot as plt

# Define patient age data
ages = [5, 12, 17, 18, 22, 25, 29, 34, 38, 41, 45, 52, 60, 67, 75, 80, 85]

# Define age bins
bins = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]

# Create the histogram
plt.figure(figsize=(8, 5))
plt.hist(ages, bins=bins, edgecolor='black', color='skyblue')

# Add labels and title
plt.title('Age Distribution')
plt.xlabel('Age Group')
plt.ylabel('Number of Patients')

# Show grid
plt.grid(axis='y', linestyle='--', alpha=0.7)

# Show the plot
plt.show()

5. 🔍 Scatter Plot – For Correlation Analysis


Scatter plots are ideal for identifying relationships or correlations between two numerical variables.

When to use: You’re analyzing relationships or correlations between two numeric variables (e.g., hours studied vs. test scores).


# Import the plotting libraries
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

# Define data
data = {
    'Bilirubin_Total': [1.2, 2.5, 0.8, 1.5, 3.0, 2.2, 1.8, 0.9, 1.3, 2.8],

    'Bilirubin_Direct': [0.3, 1.1, 0.2, 0.6, 1.4, 0.9, 0.7, 0.3, 0.4, 1.2]

}

# Convert data to DataFrame
df = pd.DataFrame(data)

# Plot with regression line
plt.figure(figsize=(8, 5))
sns.regplot(x='Bilirubin_Total', y='Bilirubin_Direct', data=df, color='purple', marker='o', scatter_kws={'s': 60})

# Add labels and title
plt.title('Bilirubin Direct vs. Bilirubin Total (with Regression Line)')
plt.xlabel('Bilirubin Total (mg/dL)')
plt.ylabel('Bilirubin Direct (mg/dL)')

plt.grid(True)

# Show the plot
plt.show()

  1. 🌞 Sunburst Chart – For hierarchical data 


A Sunburst chart is a multi-level, radial visualization that displays hierarchical data through concentric rings. Each level of the hierarchy is represented by a ring, with the center representing the root node.

When to use: Break down population by Age → Gender → Region


# Import the plotting library
import plotly.express as px
import pandas as pd

# Define data
data = {'Age Group': ['18-30', '18-30', '31-45', '31-45', '46-60', '46-60', '60+', '60+'],

  'BMI Level': ['Normal', 'Overweight', 'Normal', 'Obese', 'Overweight', 'Obese', 'Normal', 'Overweight'],

  'Count': [40, 30, 50, 20, 35, 25, 15, 10]
}

# Convert data to DataFrame
df = pd.DataFrame(data)

# Create sunburst chart
fig = px.sunburst(
				df,
    			path=['Age Group', 'BMI Level'],
    			values='Count',
  				title='Distribution of BMI Levels Across Age Groups',
                 width = 600,
				height = 600
)

# Show the chart
fig.show()



📌 Final Thoughts


These chart types form the foundation of any data analyst’s visualization toolkit:


  • Line chart – Trends

  • Bar chart – Category comparisons

  • Pie chart – Proportions

  • Histogram – Distributions

  • Scatter plot – Correlations

  • Sunburst chart - Hierarchical Data


By mastering these basics, data analysts can not only explore their datasets more effectively but also present their findings in a compelling, visual manner.

Happy charting!



+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page