Skip to content

deepanshuaggarwal51/python_mpl_json

Repository files navigation

Matplotlib rcParams JSON/YAML Schema

This repository ships a JSON Schema that describes all valid Matplotlib rcParams keys, value types and allowed enumerations.

The goal is to let you write your Matplotlib configuration in YAML, get IDE‑level validation via yaml‑language‑server (YLS), and load the settings into Python with a single call.

Directory layout

.
|- load_rcparams.py                     # helper script
|- matplotlib-rcparams-schema.json      # the JSON Schema file
|- mpl_rcparams.yml                     # sample YAML configuration
|- README.md                            # (this file)

1 directory, 4 files

Writing the rcParams YAML

The YAML file must be a mapping where each top‑level key corresponds to a Matplotlib rcParam name. Values follow the types defined in the schema (string, number, boolean, list, etc.).

Example (mpl_rcparams.yml)

# yaml-language-server: $schema=matplotlib-rcparams-schema.json

figure:
  figsize: [8, 6]
  dpi: "high"
  autolayout: true

axes:
  titlesize: large
  labelsize: 12
  grid: true

lines:
  linewidth: 2.5
  linestyle: '--'
  color: '#1f77b4'

savefig:
  bbox: "tight"
  pad_inches: 1e-2

The schema will flag:

  • wrong types (e.g., dpi: "high" → error)

Loading the YAML at runtime

A tiny helper script load_rcparams.py reads the YAML and updates Matplotlib’s rcParams.

from pathlib import Path

import matplotlib.pyplot as plt
import yaml

# loading the yaml file and converting as a python's dictionary
mpl_yaml_file = Path("mpl_rcparams.yml")
rcparams = yaml.safe_load(mpl_yaml_file.read_text())

# changing the matplotlib rcParams
for k in rcparams:
    plt.rc(group=k, **rcparams[k])

About

Python matplotlib rcParams YAML/JSON schema file. This file can be used to validate the key-value pairs for customizing the default matplotlib rcParams.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages