Skip to content

graphcore-research/gcplotlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcplotlib

A matplotlib styling library for Graphcore style-guide compliant plotting with matplotlib.

Overview

gcplotlib provides a simple interface to apply a custom style guide to matplotlib plots. It includes support for custom fonts (Graphik), color palettes, and styling that automatically propagates to seaborn.

Installation

# Navigate to the package directory
git clone git@github.com:graphcore-research/gcplotlib.git 
cd gcplotlib

# Install in editable mode
pip install -e .

# Or with optional dependencies (Jupyter, seaborn)
pip install -e ".[dev]"

Or with pip

python -m pip install git+https://github.com/graphcore-research/gcplotlib.git

Verify Installation

python test_install.py

Usage

Basic Usage

import gcplotlib
import matplotlib.pyplot as plt

# Apply the style guide
gcplotlib.init()

# Create your plots
plt.plot([1, 2, 3], [1, 4, 9])
plt.title("My Styled Plot")
plt.show()

# Reset to defaults when done (optional)
gcplotlib.reset()

With Custom Parameters

# Larger fonts for presentations
gcplotlib.init(font_scale=1.5, context="talk")

# With custom matplotlib rcParams overrides
gcplotlib.init(
    font_scale=1.2,
    **{
        "figure.figsize": (12, 8),
        "lines.linewidth": 3,
        "grid.alpha": 0.5
    }
)

Parameters

  • font_scale (float): Scaling factor for font sizes. Default: 1.0
  • context (str): Seaborn context for scaling plot elements. Options: "paper", "notebook", "talk", "poster". Default: "notebook"
  • style (str): Grid style. Options: "whitegrid", "darkgrid", "white", "dark", "ticks". Default: "whitegrid"
  • **overrides: Additional rcParams to override

Accessing Colors

import gcplotlib

# Access the color palette directly
colors = gcplotlib.GC_PALETTE
# ["#ff6f79", "#b5e4eb", "#fbe8aa", "#fbc3aa", "#292c31", "#d9d9d9", "#faf9f9"]

# Access individual colors
black = gcplotlib.GC_BLACK  # "#292c31"
grid_color = gcplotlib.GC_GRID_COLOR  # "#D9D9D9"

Example

See example.ipynb for a complete demonstration showing:

  • Before and after styling comparison
  • How to use custom overrides
  • Color palette visualization

Color Palette

  • #ff6f79 - Coral red
  • #b5e4eb - Light blue
  • #fbe8aa - Light yellow
  • #fbc3aa - Peach
  • #292c31 - Dark gray (text color)
  • #d9d9d9 - Light gray
  • #faf9f9 - Off-white

API Reference

Functions

gcplotlib.init(font_scale=1.0, context="notebook", style="whitegrid", **overrides)

Initialize matplotlib with gcplotlib styling. Changes propagate to seaborn automatically.

gcplotlib.reset()

Reset matplotlib to its original defaults.

Constants

  • gcplotlib.GC_PALETTE - List of 7 colors
  • gcplotlib.GC_BLACK - Text color (#292c31)
  • gcplotlib.GC_GRID_COLOR - Grid color (#D9D9D9)

Troubleshooting

Fonts not appearing

If the Graphik fonts aren't showing up, make sure the font files exist in gcplotlib/Graphik/:

  • Graphik-Regular.otf
  • Graphik-Medium.otf

Import errors

If you get import errors:

  1. Make sure you installed the package: pip install -e .
  2. Check that you're in the correct Python environment
  3. Try reinstalling: pip uninstall gcplotlib && pip install -e .

License

MIT

About

Graphcore style-guide compliant plotting with matplotlib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published