Skip to content

feat: Add SVG and PDF vector export for statistical plots#124

Open
dataCenter430 wants to merge 3 commits intollmsresearch:mainfrom
dataCenter430:feat/add-SVG-and-PDF-vector-export-for-statistical-plots
Open

feat: Add SVG and PDF vector export for statistical plots#124
dataCenter430 wants to merge 3 commits intollmsresearch:mainfrom
dataCenter430:feat/add-SVG-and-PDF-vector-export-for-statistical-plots

Conversation

@dataCenter430
Copy link
Copy Markdown

PR Description

This pull request adds vector format export (SVG and PDF) for statistical plots, enabling publication-ready figures for academic venues such as NeurIPS, ICML, and ICLR with no new dependencies.

Related Issue: Closes #97


Key Changes

New CLI Flag (paperbanana generate):

  • --vector / --no-vector — exports SVG and PDF alongside the raster output for statistical plots
  • Non-breaking; defaults to False, leaving MCP server and batch runner unaffected

VisualizerAgent (paperbanana/agents/visualizer.py):

  • _execute_plot_code() — strips any VLM-injected VECTOR_PATH_* assignments, injects authoritative VECTOR_PATH_SVG / VECTOR_PATH_PDF variables into the script header, and appends plt.savefig() calls for each requested format after user code
  • run() / _generate_plot() — accept vector_formats parameter; results stored in self._last_vector_paths after each execution
  • State is reset to {} at the start of every run() call to prevent bleed between iterations

Settings (paperbanana/core/config.py):

  • vector_export: bool = False — new field on Settings
  • VectorFormat = Literal["svg", "pdf"] — type alias for valid vector formats
  • YAML key output.vector_export supported via _flatten_yaml

Pipeline (paperbanana/core/pipeline.py):

  • Derives vector_formats from settings.vector_export in both generate() and continue_run()
  • Writes vector_output_paths dict to metadata.json when vector files are produced
  • Vector export is silently skipped for methodology diagrams (image-gen path, not matplotlib)

Usage

# JSON
paperbanana plot --data results.json --intent "..." --vector

# CSV
paperbanana plot --data results.csv --intent "..." --vector



Output when --vector is used:

Done! Plot saved to: outputs/run_.../final_output.png
Vector (SVG): outputs/run_.../plot_iter_1.svg
Vector (PDF): outputs/run_.../plot_iter_1.pdf

@dataCenter430
Copy link
Copy Markdown
Author

dataCenter430 commented Mar 26, 2026

Hi, @dippatel1994 I hope you're doing well.
This is my first PR, would you plesae review the PR?
Please share me your feedback fully.
Thank you.

Copy link
Copy Markdown
Member

@dippatel1994 dippatel1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feature design. Three things to fix:

  1. Windows tests fail — path injection bugVECTOR_PATH_{fmt} = "{vec_path}" uses f-string with unescaped backslashes. On Windows, C:\Users\... has \U which is an invalid unicode escape → SyntaxError. Fix with repr(path) or path.replace('\\', '/'). Same pre-existing bug on OUTPUT_PATH — fix both while you're here.

  2. Lint fails — 3 ruff errors: two E501 (line too long) in visualizer.py and cli.py, one F401 (unused import pytest) in test file.

  3. VectorFormat type alias defined but never usedpaperbanana/core/config.py adds VectorFormat = Literal["svg", "pdf"] but it's never imported or referenced. Either use it to type-annotate vector_formats or remove it.

@dataCenter430
Copy link
Copy Markdown
Author

Thanks for your response, @dippatel1994
I understood the CI failure cause fully.
I will them you mentioned soon.
Thank you.

Copy link
Copy Markdown
Member

@dippatel1994 dippatel1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows path bug and VectorFormat removal are fixed, nice work. Tests all pass now including Windows.

Lint still fails though. It's a formatting issue, not a code error. Run ruff format paperbanana/agents/visualizer.py tests/test_agents/test_visualizer.py and push.

@dataCenter430
Copy link
Copy Markdown
Author

Windows path bug and VectorFormat removal are fixed, nice work. Tests all pass now including Windows.

Lint still fails though. It's a formatting issue, not a code error. Run ruff format paperbanana/agents/visualizer.py tests/test_agents/test_visualizer.py and push.

Okay, thanks for your active response.
I will do it right now.

@dataCenter430
Copy link
Copy Markdown
Author

Just done!
now it should work successfully.
Really hope your review again.
Thanks

Copy link
Copy Markdown
Member

@dippatel1994 dippatel1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All issues fixed. Windows path bug resolved, lint clean, VectorFormat removed. CI fully green. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add SVG and PDF vector export for statistical plots

2 participants