Matplotlib vs Seaborn vs Plotly: Which Python Visualization Library Should You Use?
The same chart in Matplotlib, Seaborn and Plotly, with honest trade-offs for reports, notebooks and interactive dashboards.
Python gives you several excellent visualization libraries, but they aren't interchangeable. Pick the wrong one and you'll either fight it for every small change, or ship a beautiful interactive chart to someone who needed a PDF.
Let's build the same chart in all three and see where each one shines.
The data
Monthly revenue for two regions, in thousands of rupees:
import pandas as pd
sales = pd.DataFrame({
"month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] * 2,
"region": ["North"] * 6 + ["South"] * 6,
"revenue": [120, 135, 150, 148, 170, 190, 90, 110, 105, 130, 140, 160],
})This is "long" format: one row per month per region. Seaborn and Plotly love it. Matplotlib makes you do a little more work, as you'll see.
Matplotlib: full control, more typing
Matplotlib is the foundation. Think of it as a set of paints and brushes. You can paint anything, but you paint every stroke yourself.
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(8, 4))
for region, part in sales.groupby("region"):
ax.plot(part["month"], part["revenue"], marker="o", label=region)
ax.set_title("Monthly revenue by region")
ax.set_ylabel("Revenue (₹ thousand)")
ax.legend()
fig.tight_layout()
fig.savefig("revenue_matplotlib.png", dpi=150)Notice the loop. Matplotlib doesn't understand "colour by region"; you split the data and draw each line yourself. That's the trade: more code, but every element (each tick, label, line width, annotation) is yours to adjust.
Use it for: reports, research papers, print, and any chart that must match an exact style.
Seaborn: statistical charts in one line
Seaborn sits on top of Matplotlib and speaks "data frame". You tell it which columns mean what, and it handles grouping, colours and legends.
import seaborn as sns
sns.set_theme(style="whitegrid")
ax = sns.lineplot(data=sales, x="month", y="revenue", hue="region", marker="o")
ax.set_title("Monthly revenue by region")
plt.savefig("revenue_seaborn.png", dpi=150)hue="region" replaced the whole loop. And because the result is a normal Matplotlib chart, you still use ax.set_title and savefig.
Seaborn's real strength is statistics. Comparing the spread of order values across regions takes one line:
# orders: one row per order, with "region" and "order_value" columns
sns.boxplot(data=orders, x="region", y="order_value")That chart shows medians, quartiles and outliers. Building it in raw Matplotlib means calculating the groups yourself. Seaborn also does histograms with density curves (histplot), correlation heatmaps (heatmap) and pairwise scatter grids (pairplot) with similar ease.
Use it for: exploring data, statistical comparisons, and good-looking static charts with minimal code.
Plotly: interactive charts for the browser
Plotly produces charts that live in a web page: hover to see exact values, zoom into a range, click the legend to hide a series.
import plotly.express as px
fig = px.line(sales, x="month", y="revenue", color="region",
markers=True, title="Monthly revenue by region")
fig.show() # opens in a notebook or browser
fig.write_html("revenue.html") # a standalone interactive pageThe code is as short as Seaborn's, and color="region" does the grouping. The output is different in kind: it's an interactive HTML chart, not an image.
Saving a static PNG from Plotly needs an extra package (Kaleido): fig.write_image("revenue.png").
Use it for: dashboards, web apps, and anything people will explore rather than just look at. It plugs straight into Streamlit, as in this sales dashboard tutorial.
Side by side
Think of three ways to watch a football match. Matplotlib is the director's chair: you choose every camera angle. Seaborn is the TV broadcast: great angles chosen for you, good enough for nearly everyone. Plotly is the streaming app: viewers rewind, zoom and switch views themselves.
| Matplotlib | Seaborn | Plotly | |
|---|---|---|---|
| Code length | Longest | Shortest for stats charts | Short |
| Output | Static image | Static image | Interactive HTML |
| Customisation | Everything | Good, plus Matplotlib underneath | Good, through the figure API |
| Statistical charts | Manual | Built in | Many built in |
| Best home | Reports, papers | Notebooks, exploration | Dashboards, web pages |
| File weight | Small PNG/SVG | Small PNG/SVG | HTML with the Plotly script (several MB unless loaded from a CDN) |
What goes wrong
- Using Plotly for an email report. Interactive HTML often doesn't survive email clients or PDF export. Send a PNG.
- Fighting Matplotlib for a five-minute chart. If you're just exploring, Seaborn gets you there with far less code.
- Huge Plotly files. Every standalone HTML file embeds the whole Plotly library by default. Use
fig.write_html("chart.html", include_plotlyjs="cdn")to keep it small. - Wide data with Seaborn or Plotly. Both expect long format. If your months are columns, reshape with
df.melt(...)first.
Which one should you pick?
- Writing a report or paper: Matplotlib, styled with
sns.set_theme()if you like Seaborn's look. - Exploring a dataset in a notebook: Seaborn.
- Building a dashboard or something people will click on: Plotly.
Most working analysts use all three. Start your charts from clean data and a repeatable EDA workflow, and the library choice becomes about the audience, not the code.
In one line: Matplotlib for control and print, Seaborn for fast statistical charts, Plotly for interactive charts that live in a browser.
Keep reading
New games, tools and tutorials
About one short email a week. No spam, one-click unsubscribe.