Esta página se muestra en inglés. Una traducción al español está en curso.
SkillsApr 12, 2026·3 min de lectura

Matplotlib — Comprehensive Visualization Library for Python

Matplotlib is the foundational plotting library for Python. It creates static, animated, and interactive visualizations — from simple line plots to complex multi-panel figures — and powers the visualization backends of pandas, seaborn, and scikit-learn.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
step-1.md
Comando de instalación directa
npx -y tokrepo@latest install 10871b58-366d-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

TL;DR
Matplotlib creates static, animated, and interactive plots in Python and serves as the rendering backend for pandas, seaborn, and scikit-learn.
§01

What it is

Matplotlib is the original and most comprehensive plotting library in Python. Created in 2003, it produces static, animated, and interactive visualizations. Libraries like seaborn, pandas plotting, and scikit-learn visualization are built on top of Matplotlib.

The library targets data scientists, researchers, and engineers who need publication-quality figures. It supports line plots, scatter plots, bar charts, histograms, heatmaps, 3D surfaces, and dozens of other plot types.

§02

How it saves time or tokens

Matplotlib provides a single API for all plot types, so you learn one library and apply it everywhere. The pyplot interface mimics MATLAB, making it accessible to users coming from that ecosystem. For AI workflows, Matplotlib is the default rendering engine when you call .plot() on a pandas DataFrame or visualize model metrics in scikit-learn.

Saving figures to PNG, PDF, or SVG is a one-line call, which simplifies report generation in automated pipelines.

§03

How to use

  1. Install with pip install matplotlib.
  2. Import matplotlib.pyplot as plt and create plots using functions like plt.plot(), plt.scatter(), or plt.bar().
  3. Save with plt.savefig('output.png') or display interactively with plt.show().
§04

Example

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2 * np.pi, 100)
plt.figure(figsize=(8, 4))
plt.plot(x, np.sin(x), label='sin(x)')
plt.plot(x, np.cos(x), label='cos(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Trigonometric Functions')
plt.legend()
plt.grid(True)
plt.savefig('trig_plot.png', dpi=150)
§05

Related on TokRepo

§06

Common pitfalls

  • The pyplot state machine can produce unexpected results when creating multiple figures in a loop. Use the object-oriented API (fig, ax = plt.subplots()) for scripts that generate many plots.
  • Matplotlib renders plots in a GUI window by default. In headless environments like servers or Docker containers, set matplotlib.use('Agg') before importing pyplot to use the non-interactive backend.
  • Large datasets with millions of points cause slow rendering. Downsample your data or use rasterized=True for scatter plots to keep file sizes manageable.

Preguntas frecuentes

How does Matplotlib compare to seaborn?+

Seaborn is built on top of Matplotlib and provides a higher-level API for statistical plots. Seaborn handles data frames natively and produces styled plots with less code. Matplotlib gives you full control over every visual element but requires more code. Most users import both and switch depending on the task.

Can Matplotlib create interactive plots?+

Yes. Matplotlib supports interactive backends (Qt, Tk, notebook widgets) where you can zoom, pan, and inspect data points. For web-based interactivity, libraries like mpld3 or plotly may be more suitable, but Matplotlib covers basic interactive use cases.

Does Matplotlib work in Jupyter notebooks?+

Yes. Use `%matplotlib inline` for static plots or `%matplotlib widget` for interactive plots in Jupyter. Matplotlib is the default visualization library in most data science notebook environments.

What output formats does Matplotlib support?+

Matplotlib exports to PNG, PDF, SVG, EPS, and several other formats via savefig(). Vector formats like PDF and SVG are preferred for publications because they scale without pixelation.

Can I customize Matplotlib styles globally?+

Yes. Use plt.style.use() with built-in styles like 'ggplot', 'seaborn', or 'dark_background'. You can also create custom style sheets as .mplstyle files and load them per project. The rcParams dictionary allows fine-grained control over defaults.

Referencias (3)

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados