Skip to main content
Data AnalyticsIntermediate14 min readUpdated March 2025

Visualizing with Seaborn & Plotly

Go beyond basic plots with Seaborn for statistical graphics and Plotly for interactive charts. Build polished, shareable visuals directly from pandas DataFrames.

Choosing a Library

Python has several plotting libraries, each with a sweet spot:

  • Matplotlib — Low-level and fully customizable; the base for many others.
  • Seaborn — High-level statistical plots with attractive defaults.
  • Plotly — Interactive charts (hover, zoom, filter) that export to HTML.
  • Altair — Declarative grammar-of-graphics style for concise code.

Statistical Plots with Seaborn

Seaborn works directly with DataFrames and handles grouping, aggregation and confidence intervals for you:

python
import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
sns.set_theme(style="whitegrid")

fig, axes = plt.subplots(1, 3, figsize=(15, 4))

# Distribution
sns.histplot(data=tips, x="total_bill", kde=True, ax=axes[0])

# Category comparison with confidence intervals
sns.barplot(data=tips, x="day", y="tip", hue="sex", ax=axes[1])

# Relationship with regression line
sns.regplot(data=tips, x="total_bill", y="tip", ax=axes[2])

plt.tight_layout()
plt.show()

Interactive Charts with Plotly Express

Plotly Express builds interactive figures in a single call. Hovering reveals exact values and you can zoom or toggle series:

python
import plotly.express as px

df = px.data.gapminder().query("year == 2007")

fig = px.scatter(
    df,
    x="gdpPercap",
    y="lifeExp",
    size="pop",
    color="continent",
    hover_name="country",
    log_x=True,
    title="Life expectancy rises with GDP per capita (2007)",
)
fig.update_layout(template="plotly_white")
fig.write_html("gapminder.html")  # shareable file
fig.show()

Heatmaps for Correlations

A correlation heatmap quickly shows which numeric columns move together:

python
corr = tips.select_dtypes("number").corr()

sns.heatmap(
    corr,
    annot=True,
    fmt=".2f",
    cmap="coolwarm",
    vmin=-1, vmax=1,
    square=True,
)
plt.title("Correlation matrix")
plt.show()

Key Takeaways

  • Seaborn gives attractive statistical plots with minimal code.
  • Plotly adds interactivity and exports shareable HTML.
  • Pass DataFrames directly and map columns to visual channels.
  • Use heatmaps to scan many variable relationships at once.

Contact Us

Have a question or feedback? Fill out the form below or reach us directly at support@nvaitraining.com