Add interactive plot editor with live preview and data protection#2
Closed
brycewang-stanford wants to merge 1 commit into
Closed
Add interactive plot editor with live preview and data protection#2brycewang-stanford wants to merge 1 commit into
brycewang-stanford wants to merge 1 commit into
Conversation
Introduce sp.interactive(fig) — a Stata-inspired plot editor that allows cosmetic editing of matplotlib figures while locking statistical data elements. Key features: - Live preview: Jupyter Image widget re-renders on every edit via on_refresh callbacks - Data protection: DATA/FIT/CI artists are position-locked; axis limits auto-expand with 2% margin to prevent hiding data points - Artist classification: label-based keyword matching with word boundaries (regex) - Full style controls: color, linewidth, linestyle, alpha, marker, scatter color - Font system: 10 academic presets (AER, Nature, IEEE, 中文学位论文, etc.) + manual font family/name selection with Chinese font support - 30+ themes: StatsPAI (4) + matplotlib (10) + seaborn (16) via unified set_theme() - Code generation: deduped, clean float formatting, auto-adds imports - Undo/Reset: full state snapshot including line/collection styles - Save/Export: PNG/PDF with configurable DPI - Safe replay: method dispatch instead of exec() for undo operations - Memory-safe: editor stored on fig._statspai_editor (no global dict leak) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
brycewang-stanford
added a commit
that referenced
this pull request
Apr 20, 2026
…in check_identification Closes trade-offs #1 and #2 from v0.9.3+1 retrospective. New capabilities on sp.check_identification(): 1. DAG-based bad-control detection (trade-off #2) - New ``dag=`` parameter accepting an sp.DAG. - When supplied, runs dag.bad_controls(treatment, outcome) (Cinelli-Forney-Pearl 2022) and flags mediators, descendants, colliders, and M-bias structural problems as BLOCKERS. - Also verifies the covariate set satisfies one of the DAG's adjustment sets; suggests the shortest valid adjustment set when the user's covariate list fails. - Catches the M-bias case where the correlation heuristic is silent (collider with low treatment correlation). 2. Strict mode - New ``strict=True`` parameter. When the report's verdict is 'BLOCKERS', raises IdentificationError with the full report attached on ``err.report`` so downstream code can still inspect findings without re-running. - IdentificationError exposed at sp.IdentificationError. - Default strict=False preserves existing return-a-report behaviour. 3. IV first-stage F check - When design='iv' with an instrument column, computes the first-stage F (OLS of d on z) and flags: F < 5 -> blocker (weak identification fails) F < 10 -> warning (Staiger-Stock 1997) F < 30 -> info (moderate strength) F >= 30 -> silent (comfortable) 6 new tests (4 DAG + strict mode + IV-strength). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sp.interactive(fig)— a Stata-inspired plot editor with live preview in Jupyter (Image widget re-renders on every edit)sp.set_theme()supporting StatsPAI (4), matplotlib (10), and seaborn (16) stylesTest plan
python3 -c "from statspai.plots.interactive import FigureEditor; print('OK')"to verify importstest-notebooks/demo_graph.ipynbin Jupyter to test live previeweditor.set_xlim(-2, 2)on data spanning [-5, 5] should warn and auto-expandsp.set_theme('ggplot')andsp.set_theme('seaborn-whitegrid')workeditor.apply_font_preset('AER / Econometrica')sets correct font and sizes🤖 Generated with Claude Code