Python Origin Plotting
Use this skill to turn tabular data and plotting requirements into reproducible OriginPro projects driven by Python originpro.
Prerequisites
- Windows with OriginPro installed and licensed.
- Python that can import
originproandpandas. - Input data supplied by the user as Excel or CSV.
- No API keys or secret environment variables are required.
Security Notes
- Inspect
scripts/originpro_plot_template.pybefore running it in a new environment. - Do not commit or publish user data files, generated figures, audit CSV files, or
.opjuprojects. - Keep script outputs inside the user-selected project/output folder and an explicit temp folder such as
E:/origin_tmp. - Do not download remote code or send user data to network services as part of this skill.
First Pass
- Locate existing artifacts before writing code:
*origin*.py,*.opju,*.opj,plots_origin/, exportedOrigin_*.png- PowerShell:
Get-ChildItem -Recurse -File -Include *origin*.py,*.opju,*.opj,*.png
- Identify the input file, sheet name, required columns, desired chart types, output folder, and whether Origin should be visible.
- Reuse any existing project script style first, especially workbook setup, LabTalk styling, export naming, and temp-path handling.
- For a new project, copy and adapt
scripts/originpro_plot_template.py.
Standard Workflow
Load and clean data with
pandas.- Read Excel or CSV.
- Drop rows missing required plotting columns.
- Sort data in the expected visual order.
- Create short axis labels while preserving long labels in separate worksheet columns.
- Export an audit CSV such as
origin_input_data_sorted.csvwithencoding="utf-8-sig".
Start a clean Origin project.
import originpro as opop.set_show(True)when the user should see Origin.op.new()before creating new workbooks and graph pages.- Create a workbook with
op.new_book(...), write the DataFrame withwks.from_df(df), then set column designations and labels.
Create graphs in Origin.
- Use Origin graph pages and layers rather than matplotlib when the user asks for Origin output.
- Add plots with
gl.add_plot(wks, coly=..., colx=..., type=...). - For dual-axis charts, add a second layer and explicitly manage right-Y axis titles and limits.
Style through Origin APIs and LabTalk.
- Set axis titles with
gl.axis("x").titleandgl.axis("y").title. - Use
gl.lt_exec(...)orgp.lt_exec(...)for labels, legends, grids, tick rotation, and template-specific styling. - Call
gl.rescale()after adding plots. - Avoid graph titles when they overlap exports; prefer page long names and filenames.
- Set axis titles with
Export figures and save the Origin project.
- Export PNG/TIFF with
gp.save_fig(...). - Save
.opjuwithop.save(...). - If output paths contain Chinese characters or Origin refuses direct export, save first to an ASCII temp directory, then copy to the final path.
- Use timestamped or versioned
.opjunames if the final project file may be locked.
- Export PNG/TIFF with
Close Origin cleanly.
- Put save/export logic in
try. - Put
op.exit()infinally. - Do not leave hidden Origin COM sessions running.
- Put save/export logic in
References
Read these only when needed:
references/originpro-workflow.md: detailed implementation patterns, chart recipes, and script structure.references/troubleshooting.md: commonoriginpro, COM, Chinese-path, export, and locked-file failures.
Validation Checklist
- The script runs without Python exceptions on the target machine.
- Output folder contains an audit CSV, exported figure files, and a saved
.opju. - Figure files are non-empty and have recent modification times.
- The
.opjuopens in Origin and contains the worksheet plus graph pages. - If Origin or
originprois not installed, say so clearly and do not fake Origin output with matplotlib unless the user asks for a fallback.
Source: Gerry2024-hub/Gerry2024-hub-python-origin-plotting-skill — distributed by TomeVault.