matplotlib

Low-level plotting library for full customization. Use when you need fine-grained control over every plot element, creating novel plot types, or integrating with specific scientific workflows. Export to PNG/PDF/SVG for publication. For quick statistical plots use seaborn; for interactive plots use plotly; for publication-ready multi-panel figures with journal styling, use scientific-visualization.

Install

Hot:24

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-skills-matplotlib&locale=en&source=copy

Matplotlib - A Complete Guide to Python Data Visualization Plotting Library

Skills Overview


Matplotlib is a fundamental Python visualization library for creating static, animated, and interactive charts. It offers a complete plotting solution, ranging from simple line charts to complex, publication-quality scientific figures.

Use Cases


  • Research Papers and Academic Publishing: Create multi-panel scientific charts that meet journal requirements. Supports high-quality export formats such as PNG, PDF, and SVG, suitable for submission and presentations.

  • Data Analysis and Exploration: Perform interactive data visualization in Jupyter Notebook, supporting quick generation of various chart types such as line charts, scatter plots, and heatmaps.

  • Custom Chart Development: When you need fine-grained control over every chart element (colors, fonts, layout), or you want to develop novel visualization types integrated into specific scientific workflows.
  • Core Features


  • Diverse Chart Types: Supports common chart types including line plots, scatter plots, bar charts, histograms, heatmaps, contour plots, box plots, violin plots, and advanced visualizations such as 3D surface plots and 3D scatter plots.

  • Two-Layer API Design: Provides a pyplot interface (MATLAB-style) for quick plotting, and an object-oriented interface (Figure/Axes) for precise control over complex charts—covering everything from simple needs to advanced requirements.

  • Professional Styling and Export: Includes built-in style sheets and an rcParams configuration system. Supports 300 DPI high-resolution export, transparent backgrounds, and vector formats (PDF/SVG), ensuring charts meet publication standards.
  • Frequently Asked Questions

    How to set Chinese display in matplotlib?


    Chinese display issues usually require font configuration. You can solve it in the following ways:
    import matplotlib.pyplot as plt
    plt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS', 'DejaVu Sans']
    plt.rcParams['axes.unicode_minus'] = False  # Fix negative sign display issues

    If your system lacks Chinese fonts, install the corresponding font package or use another font that includes Chinese characters.

    What is the difference between matplotlib and seaborn, and which should I use?


    Matplotlib is a low-level plotting library that offers fine control but requires more code. Seaborn is built on top of matplotlib, providing a high-level statistical chart interface with simpler code but weaker customization. Recommendations:
  • Quick statistical charts: use seaborn

  • Publication-grade customized charts: use matplotlib

  • Complex multi-panel layouts: use matplotlib’s object-oriented interface

  • You can combine them: generate with seaborn and then fine-tune with matplotlib
  • How to save high-resolution images for paper submissions?


    Use the savefig() method and set appropriate parameters:
    fig.savefig('figure.png', dpi=300, bbox_inches='tight', facecolor='white')

    Key parameters:
  • dpi=300: publication-level resolution (150 for web, 72 for screen)

  • bbox_inches='tight': automatically crop extra whitespace

  • facecolor='white': ensure a white background

  • Supports exporting to PDF/SVG vector formats to prevent distortion when scaling up
  • How to use matplotlib in a Jupyter notebook?


    First install an interactive backend:
    uv add matplotlib ipympl

    Then run in the notebook:
    %matplotlib widget  # or %matplotlib ipympl

    This allows charts to be interactively zoomed and manipulated within the notebook. If interaction is not needed, use %matplotlib inline.

    Is matplotlib suitable for interactive visualization?


    Matplotlib is mainly designed for static charts and animations. Although it supports basic interactivity (such as zooming and panning), for complex interactive visualizations (like hover tooltips and dynamic updates), it’s recommended to use specialized interactive visualization libraries such as plotly or bokeh. Matplotlib is better suited for generating final static outputs.

    How to create multi-subplot layouts?


    Matplotlib provides three layout methods:
  • Regular grid: Use plt.subplots(2, 2) to create a 2×2 grid

  • Mosaic layout: Use plt.subplot_mosaic() to flexibly arrange subplots

  • GridSpec: Maximum control, precisely specify the position of each subplot
  • For the object-oriented interface, it’s recommended to use constrained_layout=True to automatically handle spacing between subplots and prevent element overlap.