Comprehensive Python library for creating static, animated, and interactive visualizations
—
A comprehensive Python library for creating static, animated, and interactive visualizations. Matplotlib provides publication-quality figures across various output formats and interactive environments, serving as the foundational plotting library for the Python scientific ecosystem.
pip install matplotlibimport matplotlibCommon for working with plots:
import matplotlib.pyplot as pltObject-oriented interface:
from matplotlib.figure import Figure
from matplotlib.axes import Axes
import matplotlib.patches as mpatches
import matplotlib.colors as mcolorsimport matplotlib.pyplot as plt
import numpy as np
# Create sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Create a simple line plot
plt.figure(figsize=(10, 6))
plt.plot(x, y, 'b-', linewidth=2, label='sin(x)')
plt.xlabel('X values')
plt.ylabel('Y values')
plt.title('Simple Sine Wave Plot')
plt.legend()
plt.grid(True)
plt.show()
# Create a scatter plot
plt.figure(figsize=(8, 6))
plt.scatter(x[::10], y[::10], c='red', s=50, alpha=0.7)
plt.xlabel('X values')
plt.ylabel('Y values')
plt.title('Scatter Plot')
plt.show()The Artist hierarchy enables matplotlib's flexibility and extensibility:
This design allows every visual element to be customized and provides the foundation for matplotlib's role as the base plotting library for the Python scientific ecosystem, including integration with NumPy, pandas, Jupyter notebooks, and hundreds of domain-specific visualization libraries.
State-based MATLAB-like interface providing simple plotting functions for quick visualizations. Includes figure management, basic plots, statistical plots, and 2D visualizations with automatic state handling.
def plot(*args, **kwargs): ...
def scatter(x, y, **kwargs): ...
def bar(x, height, **kwargs): ...
def hist(x, **kwargs): ...
def imshow(X, **kwargs): ...
def figure(num=None, figsize=None, **kwargs): ...
def show(**kwargs): ...
def savefig(fname, **kwargs): ...Direct manipulation of Figure and Axes objects for complex layouts and fine control. This approach provides maximum flexibility for custom visualizations and programmatic plot generation.
class Figure:
def add_subplot(self, *args, **kwargs): ...
def add_axes(self, rect, **kwargs): ...
def savefig(self, fname, **kwargs): ...
class Axes:
def plot(self, *args, **kwargs): ...
def scatter(self, x, y, **kwargs): ...
def set_xlabel(self, xlabel, **kwargs): ...
def set_ylabel(self, ylabel, **kwargs): ...
def legend(self, **kwargs): ...Comprehensive color management with built-in colormaps, color conversion utilities, and styling systems. Supports custom colormaps, normalization, and global style configuration.
# Color conversion
def to_rgba(c, alpha=None): ...
def to_hex(c, keep_alpha=False): ...
# Colormaps
class Colormap:
def __call__(self, X, alpha=None, bytes=False): ...
# Configuration
rcParams: dict
def rc(group, **kwargs): ...
def use(style): ...Drawing primitive shapes and complex geometric objects. Includes rectangles, circles, polygons, arrows, and custom patches with styling options.
class Rectangle:
def __init__(self, xy, width, height, **kwargs): ...
class Circle:
def __init__(self, xy, radius, **kwargs): ...
class Polygon:
def __init__(self, xy, **kwargs): ...
class Arrow:
def __init__(self, x, y, dx, dy, **kwargs): ...Creating animated plots and interactive visualizations. Supports function-based and artist-based animations with multiple export formats.
class FuncAnimation:
def __init__(self, fig, func, frames=None, **kwargs): ...
class ArtistAnimation:
def __init__(self, fig, artists, **kwargs): ...
def save(self, filename, writer=None, **kwargs): ...Three-dimensional visualization capabilities through the mplot3d toolkit. Supports 3D line plots, surface plots, scatter plots, and wireframes.
from mpl_toolkits.mplot3d import Axes3D
class Axes3D:
def plot(self, xs, ys, zs, **kwargs): ...
def scatter(self, xs, ys, zs, **kwargs): ...
def plot_surface(self, X, Y, Z, **kwargs): ...
def plot_wireframe(self, X, Y, Z, **kwargs): ...Output format control and GUI integration. Supports multiple backends for different platforms and export formats including PNG, PDF, SVG, and EPS.
def use(backend): ...
def get_backend(): ...
def switch_backend(newbackend): ...
# Export formats
def savefig(fname, dpi=None, format=None, bbox_inches=None): ...# Main configuration dictionary
rcParams: dict
# Configuration functions
def rc(group, **kwargs): ...
def rcdefaults(): ...
def rc_context(rc=None, fname=None): ...
# Backend management
def use(backend): ...
def get_backend(): ...
def interactive(b=None): ...from typing import Union, Optional, Sequence, Any
from numpy.typing import ArrayLike
# Common type aliases
ColorType = Union[str, tuple, list]
LineStyleType = Union[str, tuple]
MarkerType = Union[str, int]
ArrayLike = Union[list, tuple, 'numpy.ndarray']Install with Tessl CLI
npx tessl i tessl/pypi-matplotlib