CNSPlots
Build plots against the installed cnsplots version. Favor a short, runnable
script that preserves the user's data semantics and produces the requested
artifact.
Workflow
Inspect the input data before choosing a plot.
- Confirm the relevant columns, dtypes, missing values, units, category order, and event coding.
- Ask only when an unresolved choice would change the scientific meaning.
- Never invent labels, comparisons, thresholds, statistical tests, or units.
Choose the narrowest suitable public plot function.
- Read references/plot-catalog.md when selecting a plot type or composing a multi-panel figure.
- Prefer
import cnsplots as cnsand the public names oncns. - Do not call private modules or functions.
Verify the installed API instead of guessing a signature.
python - <<'PY' import inspect import cnsplots as cns print(cns.__version__) print(inspect.signature(cns.boxplot)) print(cns.boxplot.__doc__) PYReplace
boxplotwith the selected public function. Ifcnsplotscannot be imported, report that clearly and ask before changing the user's environment.Build the figure.
- In headless execution, set
MPLBACKEND=Aggor callmatplotlib.use("Agg")before importing plotting backends. - Start single-panel figures with
fig = cns.figure(width=..., height=...). Dimensions size the whole canvas in points (1/72 inch) by default, withunit="pt",unit="in", orunit="mm"for explicit dimensions. Omitted dimensions always use settings stored in points. The returned MatplotlibFigurebecomes current. - Pass
ax=explicitly when composing with existing Matplotlib axes. - Use
cns.multipanelfor labeled publication panels. Itsmax_widthsets the full figure width; explicit panel dimensions inherit itsunitor override it per panel. Panel sizes describe axes area, with decorations and margins adding layout space. Margins stay in points; labelpad_left/pad_topstay in rendered display pixels. - Add titles and axis labels through the returned Matplotlib axes.
- Use
cns.settings.context(...)for temporary style overrides rather than leaving global settings changed.
- In headless execution, set
Save and validate the result.
- Use
cns.savefig(..., fig=fig)to save a retained figure, or omitfigto save the current figure. Prefer SVG or PDF for editable publication output and PNG for a raster preview. Per-savedpi,transparent,bbox_inches, andpad_inchesoverride export settings;bbox_inches=Nonepreserves the full canvas, and padding in inches applies only to tight cropping. DPI controls raster resolution, not physical size:cns.figure(100, 150)is 100/72 × 150/72 inches, or a 200 × 300 pixel canvas at default display DPI 144. At default export DPI 288 it saves as 400 × 600 pixels withbbox_inches=None; default tight cropping changes the saved bounds. - Run the complete script, confirm the output exists and is non-empty, and inspect or render it when visual tools are available.
- Check clipping, unreadable labels, misleading scales, legend collisions, color distinguishability, and panel alignment.
- Return the runnable code, output path, and any scientific assumptions.
- Use
Baseline Pattern
import matplotlib
matplotlib.use("Agg")
import cnsplots as cns
fig = cns.figure(width=180, height=150)
ax = cns.boxplot(data=df, x="group", y="value")
ax.set(xlabel="Group", ylabel="Value")
cns.savefig("figure.svg", fig=fig)
Adapt this only after inspecting the selected function's installed signature and docstring.
Statistical Integrity
- Treat
pairs, event codes, reference groups, transformations, and thresholds as analysis choices, not decoration. - State tests and comparison directions reflected by the installed function documentation.
- Do not imply causality or significance beyond the supplied data and chosen analysis.
- Preserve raw observations when the user requests them; do not silently replace distributions with summaries.