Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Sktime Pytorch forecasting Matplotlib Plotting Dependencies

From Leeroopedia


Knowledge Sources
Domains Infrastructure, Visualization
Last Updated 2026-02-08 08:00 GMT

Overview

Optional dependency providing matplotlib for prediction plotting, model interpretation visualization, and data randomization plots.

Description

This environment adds the `matplotlib` package, which is used throughout pytorch-forecasting for visualization. The library uses a two-tier approach: explicit plot methods (plot_prediction, plot_interpretation) raise ImportError if matplotlib is missing, while logging methods (log_prediction, log_gradient_flow) gracefully skip plotting and continue. In CI environments (GitHub Actions), the Agg backend is auto-selected to prevent tkinter errors.

Usage

Required when calling any plot_* method on models or datasets. Also needed for log_* methods that include visual output in TensorBoard. Not needed for training, prediction, or metric computation. Install via `pip install matplotlib`.

System Requirements

Category Requirement Notes
OS Linux, macOS, or Windows Linux may need display server or Agg backend
Hardware Same as core No additional hardware requirements
Python >= 3.10 Same as core package

Dependencies

Python Packages

  • `matplotlib` (no version constraint specified)

Credentials

No credentials are required.

Quick Install

# Install matplotlib
pip install matplotlib

# Or install with all extras
pip install pytorch-forecasting[all_extras]

Code Evidence

Matplotlib check utility from `utils/_dependencies/_dependencies.py:11-20`:

def _check_matplotlib(ref="This feature", raise_error=True):
    matplotlib_present = _check_soft_dependencies("matplotlib", severity="none")
    if raise_error and not matplotlib_present:
        raise ImportError(
            f"{ref} requires matplotlib."
            " Please install matplotlib with `pip install matplotlib`."
        )
    return matplotlib_present

Graceful skip in logging from `models/base/_base_model.py:1131`:

# log_prediction: graceful skip if matplotlib not installed
if not _check_matplotlib(raise_error=False):
    return None

CI Agg backend from `tests/test_models/conftest.py:11-15`:

if _check_soft_dependencies("matplotlib", severity="none"):
    if os.environ.get("GITHUB_ACTIONS") == "true":
        import matplotlib
        matplotlib.use("Agg")

Common Errors

Error Message Cause Solution
`ImportError: ... requires matplotlib` matplotlib not installed, explicit plot method called `pip install matplotlib`
`TclError: no display name` Linux without display, interactive backend Set `matplotlib.use("Agg")` or use headless backend
Warnings during LR finder matplotlib logging noise Set `log_interval=-1` in model to suppress

Compatibility Notes

  • Headless servers (CI/Linux): Use `matplotlib.use("Agg")` to avoid display errors. The test suite auto-detects GitHub Actions and sets this.
  • Plot methods: `plot_prediction`, `plot_interpretation`, `plot_prediction_actual_by_variable`, `plot_randomization` all require matplotlib and raise ImportError if missing.
  • Log methods: `log_prediction`, `log_gradient_flow`, `log_interpretation` gracefully skip if matplotlib is not available.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment