A matplotlib styling library for Graphcore style-guide compliant plotting with matplotlib.
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.
# 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]"python -m pip install git+https://github.com/graphcore-research/gcplotlib.git
python test_install.pyimport 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()# 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
}
)font_scale(float): Scaling factor for font sizes. Default: 1.0context(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
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"See example.ipynb for a complete demonstration showing:
- Before and after styling comparison
- How to use custom overrides
- Color palette visualization
#ff6f79- Coral red#b5e4eb- Light blue#fbe8aa- Light yellow#fbc3aa- Peach#292c31- Dark gray (text color)#d9d9d9- Light gray#faf9f9- Off-white
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.
gcplotlib.GC_PALETTE- List of 7 colorsgcplotlib.GC_BLACK- Text color (#292c31)gcplotlib.GC_GRID_COLOR- Grid color (#D9D9D9)
If the Graphik fonts aren't showing up, make sure the font files exist in gcplotlib/Graphik/:
Graphik-Regular.otfGraphik-Medium.otf
If you get import errors:
- Make sure you installed the package:
pip install -e . - Check that you're in the correct Python environment
- Try reinstalling:
pip uninstall gcplotlib && pip install -e .
MIT