Визуализация в Python: matplotlib vs seaborn vs plotly

Карьерник — квиз-тренажёр в Telegram с 1500+ вопросами для собесов аналитика. SQL, Python, A/B, метрики. Бесплатно.

Зачем это знать

Каждый аналитик строит графики в Python. Matplotlib, seaborn, plotly — 3 main libraries. Right choice экономит часы frustration. На собесах могут спросить «какие используете и почему».

Краткое сравнение

matplotlib seaborn plotly
Age 2003 2012 2014
Style Low-level High-level High-level
Interactive No No Yes
Statistical Basic Strong Good
Customization Ultimate Good Good
Learning curve Steep Moderate Moderate

matplotlib

Foundation. Все другие built on top.

Pros

  • Full control
  • Any chart customizable
  • Large ecosystem

Cons

  • Verbose syntax
  • Ugly defaults
  • Time consuming

Basic

import matplotlib.pyplot as plt

plt.figure(figsize=(10, 6))
plt.plot(df['date'], df['value'])
plt.title('Daily revenue')
plt.xlabel('Date')
plt.ylabel('Revenue ($)')
plt.grid(True)
plt.show()

When use

  • Need exact customization
  • Publication quality
  • Complex multi-panel

seaborn

Built on matplotlib. Statistical focus.

Pros

  • Beautiful defaults
  • Statistical plots
  • Works well with pandas DataFrames
  • Concise code

Cons

  • Less control vs matplotlib
  • Not interactive

Basic

import seaborn as sns

sns.set_theme(style='whitegrid')

sns.lineplot(data=df, x='date', y='value')
sns.barplot(data=df, x='category', y='count')
sns.heatmap(corr_matrix, annot=True)
sns.boxplot(data=df, x='group', y='value')
sns.scatterplot(data=df, x='x', y='y', hue='category')

When use

  • Exploratory analysis
  • Statistical visualizations (distributions, correlations)
  • Quick presentable charts

plotly

Interactive charts.

Pros

  • Interactive (zoom, hover, click)
  • Web-friendly (HTML export)
  • Beautiful
  • Animations

Cons

  • Heavy (JavaScript bundle)
  • Different syntax paradigm

Basic

import plotly.express as px

fig = px.line(df, x='date', y='value', title='Revenue')
fig.show()

fig = px.scatter(df, x='x', y='y', color='category', size='size')
fig.show()

fig = px.bar(df, x='category', y='value')

When use

  • Interactive dashboards
  • Web applications
  • Executive presentations (live demo)
  • Exploratory с hover info

Практические tips

Quick exploration

# Pandas quick
df.plot(kind='line')
df['col'].hist()

Под капотом — matplotlib.

Polished analysis

# seaborn facet
g = sns.FacetGrid(df, col='category', hue='segment')
g.map(sns.lineplot, 'date', 'revenue')

Interactive report

# plotly express
fig = px.line(df, x='date', y='revenue', color='category')
fig.write_html('report.html')

Multi-panel (subplots)

matplotlib

fig, axes = plt.subplots(2, 2, figsize=(12, 8))
axes[0, 0].plot(df['a'])
axes[0, 1].scatter(df['x'], df['y'])
# и т.д.

seaborn FacetGrid

sns.FacetGrid(df, col='category').map(sns.lineplot, 'x', 'y')

plotly subplots

from plotly.subplots import make_subplots
fig = make_subplots(rows=2, cols=2)
fig.add_trace(go.Scatter(x=..., y=...), row=1, col=1)

Style consistency

Для brand-consistent charts:

# matplotlib
plt.style.use('seaborn-v0_8-darkgrid')

# seaborn
sns.set_theme(style='whitegrid', palette='pastel')

# plotly
fig.update_layout(template='plotly_white')

Specialized libs

Altair

Declarative (Grammar of Graphics). Для complex chart logic.

Bokeh

Alternative interactive. Less popular vs plotly.

Plotnine

ggplot2 port. Для R users transitioning.

Export

PNG / PDF

# matplotlib / seaborn
plt.savefig('chart.png', dpi=300)

# plotly
fig.write_image('chart.png')

HTML

# plotly
fig.write_html('report.html')

SVG

Vector format, scales well:

plt.savefig('chart.svg')

Для notebook vs deck

Notebook

seaborn / matplotlib inline. Quick.

Slides

plotly screenshots → Google Slides. Или static matplotlib saved.

Dashboards

plotly Dash, Streamlit для interactive apps.

На собесе

«Какую library используете?» All three, each для своих use cases.

«Интерактивность?» plotly или bokeh. Или Streamlit app.

«Statistical plots?» seaborn (pairplot, distplot, heatmap).

Частые ошибки

Only matplotlib

Missing nicer options. Learn seaborn minimum.

Default seaborn colors

Often ok, но sometimes bad. Customize palette.

Too interactive

Plotly feature overload → distraction.

Ugly

Default matplotlib ugly. Always style.

Связанные темы

FAQ

Best для beginners?

seaborn — balance power и easy-to-learn.

Interactive exclusively plotly?

Also Bokeh, Altair. Plotly — most popular.

Все установить?

Usually да. Each для своих tasks.


Тренируйте Python — откройте тренажёр с 1500+ вопросами для собесов.