0% found this document useful (0 votes)
9 views22 pages

Quick Data Visualization Tools in Python

The document compares Plotly and Seaborn for data visualization in Python, highlighting their strengths and ideal use cases. Plotly is preferred for interactive and shareable charts, while Seaborn excels in creating static, publication-quality visuals. The document also provides code examples for various chart types using both libraries.

Uploaded by

Dharma Ojha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views22 pages

Quick Data Visualization Tools in Python

The document compares Plotly and Seaborn for data visualization in Python, highlighting their strengths and ideal use cases. Plotly is preferred for interactive and shareable charts, while Seaborn excels in creating static, publication-quality visuals. The document also provides code examples for various chart types using both libraries.

Uploaded by

Dharma Ojha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Data Visualization Python

Q u i ck D a t a V i s u a l izat ion s M a de E s a y

D R SUB R AMA NI

Mentor
Ramisha Rani K
Ramya Dinesh
1
Seaborn vs Plotly clearly so you can see when to use each,
especially in your workflow of quick data visualizations - Python
Python - Choosing the Right Tool for Quick Visualizations
Plotly Seaborn
• Best for interactive, shareable charts with zoom, • Best for static, publication-quality charts in Python.
hover, and tooltips. • Quick to create histograms, KDEs, scatterplots,
• Ideal for dashboards, presentations, and web apps. boxplots, and heatmaps.
• Easy to add multiple layers (histograms + KDE, • Integrates seamlessly with Pandas & Matplotlib.
scatter + bubbles, etc.). • Great for data exploration & statistical analysis.
• Supports animation & interactivity effortlessly. • Limited interactive features.
• Slightly more setup for complex statistical plots
compared to Seaborn

• Workflow Tip: • Workflow Tip:


• Use Plotly. express when you need interactive • Use Seaborn for fast exploratory analysis and detailed
visualization, dashboards, or shareable results for static plots in notebooks.
stakeholders.

2
Plotly 1️⃣ Scatter Plot Seaborn
Show relationships or correlations between two variables
import [Link] as px import pandas as pd
import pandas as pd import seaborn as sns
# Sample dataset # Sample dataset
df_scatter = [Link]({ df_scatter = [Link]({
'Height': [150, 160, 170, 180, 190], 'Height': [150, 160, 170, 180, 190],
'Weight': [50, 60, 65, 80, 90], 'Weight': [50, 60, 65, 80, 90],
'Gender': ['F', 'F', 'M', 'M', 'M'] 'Gender': ['F', 'F', 'M', 'M', 'M']
}) })
fig = [Link](df_scatter, x='Height', y='Weight', color='Gender', # Simple scatter plot
title='Scatter Plot: Height vs Weight') [Link](data=df_scatter, x='Height', y='Weight',
[Link]() hue='Gender').set_title('Scatter Plot: Height vs Weight')

3
Plotly 2️⃣ Line Chart Seaborn
Track trends or changes over time
import [Link] as px import pandas as pd
import pandas as pd import seaborn as sns
# Sample dataset # Sample dataset
df_line = [Link]({ df_line = [Link]({
'Month': ['Jan','Feb','Mar','Apr','May'], 'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
'Sales': [200, 250, 300, 280, 350] 'Sales': [200, 250, 300, 280, 350]
}) })
fig = [Link](df_line, x='Month', y='Sales', title='Monthly Sales Trend') # Simple line chart
[Link]() [Link](data=df_line, x='Month', y='Sales')

4
Plotly 3️⃣ Bar Chart Seaborn
Compare categories or groups
import [Link] as px import pandas as pd
import pandas as pd import seaborn as sns
# Sample dataset # Sample dataset
df_bar = [Link]({ df_bar = [Link]({
'Fruit': ['Apple', 'Banana', 'Orange', 'Mango'], 'Fruit': ['Apple', 'Banana', 'Orange', 'Mango'],
'Quantity': [10, 15, 7, 20] 'Quantity': [10, 15, 7, 20]
}) })
fig = [Link](df_bar, x='Fruit', y='Quantity', color='Fruit', title='Fruit Quantity') # Simple bar chart
[Link]() [Link](data=df_bar, x='Fruit', y='Quantity', palette='pastel').set_title('Fruit Quantity')

5
Plotly 4️⃣ Pie Chart Seaborn
Show simple percentage or part-to-whole relationships
import [Link] as px
import pandas as pd
# Sample dataset
df_bar = [Link]({
'Fruit': ['Apple', 'Banana', 'Orange', 'Mango'],
'Quantity': [10, 15, 7, 20]
})
fig = [Link](df_bar, names='Fruit', values='Quantity', title='Fruit Distribution')
[Link]()
Seaborn does not have a built-in function.

6
Plotly 5️⃣ Donut Chart Seaborn
Same as pie, but more stylish for presentations

import [Link] as px
import pandas as pd
# Sample dataset
df_bar = [Link]({
'Fruit': ['Apple', 'Banana', 'Orange', 'Mango'],
'Quantity': [10, 15, 7, 20]
})
fig = [Link](df_bar, names='Fruit', values='Quantity', hole=0.4, title='Donut Chart Example')
[Link]()
Seaborn does not have a built-in function.

7
Plotly 6️⃣ Histogram Seaborn
Analyze frequency or data distribution
import [Link] as px import pandas as pd
import pandas as pd import seaborn as sns
# Sample dataset
df_hist = [Link]({'Scores': [45, 55, 65, 75, 85, 95, 55, 65, 75, 85]}) # Sample dataset
fig = [Link](df_hist, x='Scores', nbins=5, title='Score Distribution') df_hist = [Link]({'Scores': [45, 55, 65, 75, 85, 95, 55, 65, 75, 85]})
[Link]()
# Histogram
[Link](data=df_hist, x='Scores', bins=5, kde=False).set_title('Score Distribution')

8
Plotly 7️⃣ Box Plot Seaborn
Display data spread, outliers, and quartile
import [Link] as px import pandas as pd
import pandas as pd import seaborn as sns
# Simple dataset # Sample dataset
df_simple = [Link]({ df_simple = [Link]({
'Class': ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'], 'Class': ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'],
'Score': [75, 85, 80, 90, 60, 80, 60, 70, 85] 'Score': [75, 85, 80, 90, 60, 80, 60, 70, 85]
}) })
fig = [Link](df_simple, x='Class', y='Score', title='Box Plot of Scores') # Box plot
[Link]() [Link](data=df_simple, x='Class', y='Score').set_title('Box Plot of Scores')

9
Plotly 8️⃣ Violin Plot Seaborn
Show data distribution + density in one view
# Simple dataset import pandas as pd
df_simple = [Link]({ import seaborn as sns
'Class': ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'], # Sample dataset
df_simple = [Link]({
'Score': [75, 85, 80, 90, 60, 80, 60, 70, 85]
'Class': ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'],
}) 'Score': [75, 85, 80, 90, 60, 80, 60, 70, 85]
fig = [Link](df_simple, x='Class', y='Score', box=True, title='Violin Plot of Scores') })
[Link]() # Violin plot
[Link](data=df_simple, x='Class', y='Score', inner='box').set_title('Violin Plot of Scores')

10
Plotly 9️⃣ Bubble Chart Seaborn
Compare 3 variables (x, y, and bubble size)
import [Link] as px import pandas as pd
import pandas as pd import seaborn as sns
# Sample dataset # Sample dataset
df_bubble = [Link]({ df_bubble = [Link]({
'Country': ['A', 'B', 'C', 'D'], 'Country': ['A', 'B', 'C', 'D'],
'GDP': [1000, 2000, 3000, 4000], 'GDP': [1000, 2000, 3000, 4000],
'LifeExp': [60, 70, 65, 75], 'LifeExp': [60, 70, 65, 75],
'Population': [1.5, 2.5, 3.5, 4.5] 'Population': [1.5, 2.5, 3.5, 4.5]
}) })
# Bubble chart
fig = [Link](df_bubble, x='GDP', y='LifeExp', size='Population', color='Country', [Link](
hover_name='Country', title='Bubble Chart: GDP vs Life Expectancy') data=df_bubble, x='GDP’, y='LifeExp’, size='Population', hue='Country’,
[Link]() sizes=(100, 1000), legend='full').set_title('Bubble Chart: GDP vs Life Expectancy')

11
Plotly Treemap Seaborn
Show hierarchical data with area-based proportions
import [Link] as px
import pandas as pd
# Sample dataset
df_tree = [Link]({
'Continent': ['Asia','Asia','Europe','Europe'],
'Country': ['India','China','France','Germany'],
'Population': [140, 130, 67, 83]
})
fig = [Link](df_tree, path=['Continent','Country'], values='Population',
title='Treemap of Population by Continent') Seaborn does not have a built-in function.
[Link]()

12
Plotly 1️⃣1️⃣ Sunburst Chart Seaborn
Explore multi-level hierarchical structures

import [Link] as px
import pandas as pd
# Sample dataset
df_tree = [Link]({
'Continent': ['Asia','Asia','Europe','Europe'],
'Country': ['India','China','France','Germany'],
'Population': [1400, 1300, 67, 83]
})
fig = [Link](df_tree, path=['Continent','Country'], values='Population',
title='Sunburst Chart of Population') Seaborn does not have a built-in function.
[Link]()

13
Plotly 1️⃣2️⃣ Area Chart Seaborn
Show cumulative trends or proportions over time
import seaborn as sns
import [Link] as px import [Link] as plt
import pandas as pd # Sample dataset
# Sample dataset df_area = [Link]({
df_area = [Link]({ 'Month': ['Jan','Feb','Mar','Apr'], 'ProductA': [10, 15, 20, 25], 'ProductB': [5, 7, 10, 12]
})
'Month': ['Jan','Feb','Mar','Apr'],
# Plot Product A
'ProductA': [10, 15, 20, 25], [Link](data=df_area, x='Month', y='ProductA', label='Product A', color='blue')
'ProductB': [5, 7, 10, 12] plt.fill_between(df_area['Month'], df_area['ProductA'], alpha=0.3, color='skyblue')
}) # Plot Product B
fig = [Link](df_area, x='Month', y=['ProductB','ProductA'], title='Area Chart Example') [Link](data=df_area, x='Month', y='ProductB', label='Product B', color='green')
plt.fill_between(df_area['Month'], df_area['ProductB'], alpha=0.3, color='lightgreen')
[Link]() [Link]('Monthly Sales Area Chart')
[Link]('Month')
[Link]('Sales')
[Link]()
[Link]()

14
Plotly 1️⃣3️⃣ Heatmap Seaborn
Visualize relationships or correlations in a matrix
import [Link] as px import numpy as np
import pandas as pd import seaborn as sns
# Sample dataset # Sample data
data = [Link](5,5) data = [Link](5,5)
fig = [Link](data, text_auto=True, title='Random Heatmap') # Heatmap
[Link]() [Link](data, annot=True, cmap='magma').set_title('Random Heatmap')

15
Plotly 1️⃣4️⃣ Density Contour Seaborn
Highlight areas where data points are concentrated (great for visualizing data density or clustering)
import [Link] as px import pandas as pd
import pandas as pd import numpy as np
# Sample dataset import seaborn as sns
df_density = [Link]({ # Sample dataset
df_density = [Link]({
'X': [Link](100),
'X': [Link](100),
'Y': [Link](100)
'Y': [Link](100)
}) })
fig = px.density_contour(df_density, x='X', y='Y', title='Density Contour Plot') # Density contour plot
[Link]() [Link](data=df_density, x='X', y='Y', fill=True, cmap='Blues').set_title('Density Contour Plot')

16
Plotly 1️⃣5️⃣ Geo Map Seaborn
Display data across geographic locations
import [Link] as px
import pandas as pd
# Sample dataset
df_map = [Link]({
'Country': ['USA','CAN','MEX'],
'ISO': ['USA','CAN','MEX'],
'Population': [300, 37, 120]
})
fig = px.scatter_geo(df_map, locations='ISO', color='Country', size='Population',
projection='natural earth', title='Sample Map')
[Link]() Seaborn does not have a built-in function.

17
Plotly 1️⃣6️⃣ Animated Scatter Seaborn
Show data change dynamically over time
import [Link] as px
import pandas as pd
# Sample dataset
df_anim = [Link]({
'Year': [2000,2000,2001,2001],
'Country': ['A','B','A','B'],
'GDP': [100,200,150,250],
'LifeExp':[60,70,62,72]
})
fig = [Link](df_anim, x='GDP', y='LifeExp', animation_frame='Year', animation_group='Country',
size='GDP', color='Country', hover_name='Country', log_x=False, size_max=50,

[Link]()
title='Animated Scatter Example') Seaborn does not have a built-in function.

18
1️⃣7️⃣ Normal Distribution
Plotly with KDE Curve Seaborn
Purpose: To visualize the distribution of continuous data and see its overall shape, including where values cluster and whether it looks like a normal distribution.

import numpy as np import numpy as np


import pandas as pd import pandas as pd
import [Link] as px import seaborn as sns
from [Link] import gaussian_kde import [Link] as plt
# Sample normal distribution data # Generate sample normal distribution data
[Link](0) [Link](0)
data = [Link](loc=50, scale=10, size=200) data = [Link](loc=50, scale=10, size=200) # mean=50, std=10, 200 points
df = [Link]({'Value': data}) df = [Link]({'Value': data})
# Histogram # Plot histogram with KDE
fig = [Link](df, x='Value', nbins=20, histnorm='probability density', opacity=0.6) [Link](figsize=(8,6))
# Compute KDE [Link](df['Value'], bins=20, kde=True, color='skyblue', stat='density')
kde = gaussian_kde(data) # stat='density' makes histogram comparable to KDE
x_vals = [Link](min(data), max(data), 200) [Link]('Normal Distribution')
y_vals = kde(x_vals) [Link]('Value')
# Add KDE curve [Link]('Density')
fig.add_scatter(x=x_vals, y=y_vals, mode='lines', name='KDE', line=dict(color='red')) [Link]()
fig.update_layout(title='Normal Distribution with KDE Curve', xaxis_title='Value', yaxis_title='Density')
[Link]()

19
Supported Charts
Chart Type Seaborn Plotly
Scatter (interactive)
Line (interactive)
Bar
Box
Violin
Histogram
Heatmap
Density contour
Pie / Donut
Treemap
Sunburst
Bubble (static) (interactive)
Geo Map
Animated scatter
Area chart (static) (interactive)
20
Plotly Renderers — Quick Reference
import [Link] as px
import [Link] as pio

[Link] = "svg"

Renderer Name Environment / Use Case Description


Displays interactive Plotly
"notebook" Jupyter Notebook
charts inline (default in Jupyter).
Opens the chart in a new
"browser" Any Python environment
browser tab for full interactivity.
Renders a static vector image
"svg" Static export — useful for documents,
reports, or PPTs.
Shows a static raster image (no
"png" Static export interactivity, good for quick
snapshots).
Embeds the chart in an
"iframe" Embedded HTML interactive HTML frame inside
notebooks or web apps.
Optimized renderer for Colab
"colab" Google Colab
notebooks.

21
When to Use Each

Seaborn:
•Quick EDA (Exploratory Data Analysis)
•Static reports, papers, or slides
•Needs clean, simple charts

Plotly:
•Dashboards & web apps
•Interactive presentations
•Animations or geographic visualizations

Summary:
•Use Seaborn for speed + simplicity + static analysis.
•Use Plotly for interaction + presentation + animation
Thank You
DR SUBRAMANI

22

You might also like