5.6 KiB
pubfig architecture (source-driven)
This guide reads pubfig from the source tree rather than from high-level overview material.
Source root:
pubfig/src/pubfig/__init__.pypubfig/src/pubfig/plots/pubfig/src/pubfig/export/pubfig/src/pubfig/specs.pypubfig/src/pubfig/themes/pubfig/src/pubfig/colors/pubfig/src/pubfig/cli.py
1. Start at pubfig.__init__
The stable user-facing surface is re-exported from __init__.py.
That file tells you the package is organized into five main layers:
- plot constructors from
plots/ - export helpers from
export/ - publication sizing from
specs.py - theme and palette registries from
themes/andcolors/ - Figma/bridge helpers and related CLI support
For skill design, this is the most important architectural fact:
- figure generation lives in
plots/ - figure export lives in
export/ - venue sizing lives in
specs.py - multi-panel/Figma handoff is a separate downstream layer
The default mental model is plot first, export second, compose third.
2. Package boundaries
plots/
This is the core figure-construction layer.
Representative files:
plots/line.pyplots/comparison.pyplots/evaluation.pyplots/_grouped_scatter.py
From the source, plot functions usually do the same sequence:
- normalize/coerce input data,
- enter
theme_context(theme), - resolve design-time size via
resolve_design_dpi(...), - allocate figure/axes via
get_fig_ax(...), - style axes/legends through helpers in
_style.py, - return a Matplotlib
Figure.
Interpretation from source:
pubfigbehaves as a Matplotlib-first figure factory layer, not as a separate scene-graph runtime.
export/
This is intentionally separated from plotting.
Important files:
export/io.pyexport/panels.py
export/io.py handles normal figure export:
- coerce Figure/Axes into a real
Figure - enforce explicit suffixes
- apply publication width/height rules
- write vector or raster output
Current source implication:
batch_export(...)now belongs to the same publication-aware export layer, rather than to a simple multi-formatsavefigwrapper.
export/panels.py handles panel-level export for composite or Figma-oriented workflows:
- one panel at a time or many panels together
- optional publication-aware sizing
- optional title stripping
- metadata index generation (
panel-index.json)
specs.py
This file is the publication-sizing contract.
FigureSpec defines:
font_familydesign_dpisingle_column_mmdouble_column_mmdefault_raster_dpibackground_color
Built-in registry entries include:
naturesciencecell
The source shows a strong split between:
- design size used when constructing interactive figures,
- physical export size used when saving publication figures.
That split is why the skill should not treat width in plot calls and width in export calls as the same semantic layer.
themes/ and colors/
These are registries, not plain constants.
From __init__.py, the public surface includes:
get_theme,register_theme,set_default_themeget_palette,register_palette,show_palette
Operational implication:
- treat theme and palette selection as first-class API configuration rather than as hardcoded styling trivia.
cli.py
The current CLI is not the main figure-generation interface.
From the source, cli.py is mainly about:
- Figma bridge serving
- bundle packaging/inspection/validation
- sync job submission and waiting
- local bridge auto-start logic
So for this skill:
- Python API is the primary route for figure generation
pubfig.cliis a secondary operational layer for bridge/Figma workflows
3. Plotting architecture pattern
From line.py, comparison.py, and evaluation.py, the recurring internal pattern is:
- input normalization is local to the chart family,
- shared visual behavior is delegated to internal helpers,
- returned artifact is still a standard Matplotlib figure.
This is why the skill should map requests to a chart family first, instead of jumping directly to export or panel assembly.
Examples from source:
line.pygroups time/trend style plotscomparison.pygroups comparison-style statistical displays likedumbbellandforest_plotevaluation.pygroups metric/evaluation plots likeroc,pr_curve, andcalibration_grouped_scatter.pycontains the more specialized placement/jitter/annotation logic behind grouped scatter layouts
4. Export architecture pattern
From export/io.py and export/panels.py, pubfig uses three distinct output modes:
- single explicit artifact via
save_figure(...) - publication-aware multi-format artifact set via
batch_export(...) - panel bundle workflow via
export_panel(...)/export_panels(...)
Those are different contracts, and the skill should keep them separate in its recommendations.
5. Reading order for deep debugging
When a skill or agent needs source-level certainty, use this order:
pubfig/src/pubfig/__init__.py- relevant chart-family module in
plots/ pubfig/src/pubfig/specs.pypubfig/src/pubfig/export/io.pypubfig/src/pubfig/export/panels.pypubfig/src/pubfig/cli.pyonly if the task involves bridge/Figma sync
6. Implications for this skill
This source layout implies the skill should:
- default to Python plot API + explicit export call,
- treat publication sizing as an export concern,
- treat panel/Figma work as optional downstream composition,
- avoid presenting the CLI as the main path for ordinary figure generation,
- keep chart selection logically ahead of export tuning.