PyThesisPlot
Python scientific plotting workflow tool supporting the complete process from data upload to figure generation for academic publications.
Workflow
CODEBLOCK0
Required Steps
- 1. Data Reception: User uploads data file (txt/md/xlsx/csv)
- Auto-save: Rename to
timestamp-original_filename, save to INLINECODE1 - Data Analysis: Analyze dimensions, types, statistical features, column relationships
- Chart Recommendations: Recommend chart schemes based on data characteristics (type, quantity, layout)
- User Confirmation: Display analysis report, must wait for user confirmation before generation
- Generation & Delivery: Python code + chart images, save to same output directory
Core Scripts
1. Main Workflow Script
CODEBLOCK1
2. Data Analysis
CODEBLOCK2
Output: Data characteristics report + chart recommendation scheme
3. Chart Generation
CODEBLOCK3
File Management Standards
Directory Structure
CODEBLOCK4
Naming Conventions
| File Type | Naming Format | Example |
|---|
| Data File | INLINECODE2 | INLINECODE3 |
| Analysis Report |
analysis_report.md |
analysis_report.md |
| Python Code |
{timestamp}_plot.py |
20250312-145230_plot.py |
| Chart PNG |
{timestamp}_fig{n}_{type}.png |
20250312-145230_fig1_line.png |
Usage
Scenario 1: Complete Workflow
When user uploads a data file:
- 1. Auto-save File
CODEBLOCK5
- 2. Execute Data Analysis
CODEBLOCK6
- 3. Display Analysis Report to User
CODEBLOCK7
- 4. Wait for User Confirmation ⚠️ Critical Step
- User may say: "Generate scheme 1" / "Generate all" / "Modify XX..."
-
Must wait for explicit instruction before entering generation phase
- 5. Generate and Save
CODEBLOCK8
Scenario 2: Data Analysis Only
CODEBLOCK9
Scenario 3: Generate from Config
CODEBLOCK10
Chart Recommendation Logic
| Data Characteristics | Recommended Chart | Application |
|---|
| Time series + Numeric | Line plot | Trend display |
| Categorical + Single numeric |
Bar chart | Category comparison |
| Categorical + Distribution | Box/Violin plot | Distribution display |
| Two numeric (correlated) | Scatter (+regression) | Correlation analysis |
| Multiple numeric (correlated) | Heatmap | Correlation matrix |
| Single numeric distribution | Histogram/Density | Distribution characteristics |
| Multi-dimensional rich data | 2×2 subplots | Comprehensive display |
Supported File Formats
- - CSV:
.csv (Recommended) - Excel:
.xlsx, INLINECODE12 - Text:
.txt, .md (table format)
Dependencies
CODEBLOCK11
Reference Documents
Important Notes
- 1. User confirmation is mandatory: Must wait for user confirmation after analysis, cannot generate directly
- Unified file management: All output files saved to same output/{timestamp}-{filename}/ directory
- High-resolution output: Generate PNG at 300 DPI (suitable for publication)
- Code traceability: Generated Python code also saved to same directory for user modification
- Academic style: Charts follow top journal standards (Nature/Science/Lancet style)
PyThesisPlot
Python科学绘图工作流工具,支持从数据上传到学术出版物图表生成的完整流程。
工作流程
[用户上传数据] → [自动保存至输出目录] → [数据分析]
↓
[生成图像至输出目录] ← [代码生成] ← [用户确认方案]
必要步骤
- 1. 数据接收:用户上传数据文件(txt/md/xlsx/csv)
- 自动保存:重命名为时间戳-原始文件名,保存至output/YYYYMMDD-文件名/
- 数据分析:分析维度、类型、统计特征、列关系
- 图表推荐:根据数据特征(类型、数量、布局)推荐图表方案
- 用户确认:展示分析报告,必须在生成前等待用户确认
- 生成与交付:Python代码+图表图像,保存至同一输出目录
核心脚本
1. 主工作流脚本
bash
python scripts/workflow.py --input data.csv --output-dir output/
2. 数据分析
bash
python scripts/data_analyzer.py --input data.csv
输出:数据特征报告+图表推荐方案
3. 图表生成
bash
python scripts/plotgenerator.py --config plotconfig.json --output-dir output/
文件管理标准
目录结构
output/
└── 20250312-145230-data.csv/ # 以时间戳+文件名命名
├── 20250312-145230-data.csv # 原始数据文件(已重命名)
├── analysis_report.md # 数据分析报告
├── plot_config.json # 图表配置(用户确认后生成)
├── 20250312-145230_plot.py # 生成的Python代码
├── 20250312-145230fig1line.png # 图表(PNG图像)
└── 20250312-145230fig2bar.png
命名规范
| 文件类型 | 命名格式 | 示例 |
|---|
| 数据文件 | {时间戳}-{原始名称} | 20250312-145230-data.csv |
| 分析报告 |
analysis
report.md | analysisreport.md |
| Python代码 | {时间戳}
plot.py | 20250312-145230plot.py |
| 图表PNG | {时间戳}
fig{n}{类型}.png | 20250312-145230
fig1line.png |
使用方法
场景一:完整工作流
当用户上传数据文件时:
- 1. 自动保存文件
python
# 重命名并保存至 output/{时间戳}-{文件名}/
save
uploadedfile(input
file, outputbase=output/)
- 2. 执行数据分析
python
# 分析数据特征,生成报告
python scripts/data_analyzer.py --input output/20250312-data/data.csv
- 3. 向用户展示分析报告
markdown
## 数据分析报告
### 数据概览
- 文件:data.csv
- 维度:120行 × 5列
- 类型:3个数值列 + 2个分类列
### 列详情
| 列名 | 类型 | 描述 |
|-----|------|-----|
| 日期 | 日期时间 | 2023年1月至2023年12月 |
| 销售额 | 数值 | 均值=1250,标准差=320 |
| 区域 | 分类 | 4个类别:北/南/东/西 |
### 图表推荐
根据数据特征,推荐以下方案:
方案一:时间趋势分析 ⭐推荐
- 图表类型:折线图
- 内容:销售额随时间变化趋势
- 理由:时间序列数据,最能直观展示趋势
方案二:区域对比
- 图表类型:分组柱状图
- 内容:各区域销售额对比
- 理由:分类对比,适合展示差异
方案三:综合仪表盘
- 图表类型:2×2子图布局
- 包含:趋势线+柱状图+箱线图+相关性热力图
- 理由:数据维度丰富,全面展示
请告诉我您的需求:
- 生成方案一和方案二
- 全部生成
- 修改方案三...(提供您的修改建议)
- 4. 等待用户确认 ⚠️ 关键步骤
- 用户可能说:生成方案一/全部生成/修改XX...
-
必须等待明确指令后才能进入生成阶段
- 5. 生成并保存
python
# 生成Python代码
python scripts/plot
generator.py --config plotconfig.json
# 输出至同一目录
output/20250312-data/
├── 20250312-145230_plot.py # 代码
├── 20250312-145230fig1line.png # 图表
└── 20250312-145230fig2bar.png
场景二:仅数据分析
bash
python scripts/data_analyzer.py --input data.csv --output report.md
场景三:从配置生成
bash
python scripts/plot_generator.py --config config.json --output-dir ./
图表推荐逻辑
| 数据特征 | 推荐图表 | 应用场景 |
|---|
| 时间序列+数值 | 折线图 | 趋势展示 |
| 分类+单数值 |
柱状图 | 类别对比 |
| 分类+分布 | 箱线图/小提琴图 | 分布展示 |
| 双数值(相关) | 散点图(+回归线) | 相关性分析 |
| 多数值(相关) | 热力图 | 相关性矩阵 |
| 单数值分布 | 直方图/密度图 | 分布特征 |
| 多维丰富数据 | 2×2子图 | 综合展示 |
支持的文件格式
- - CSV:.csv(推荐)
- Excel:.xlsx,.xls
- 文本:.txt,.md(表格格式)
依赖项
pandas >= 1.3.0
matplotlib >= 3.5.0
seaborn >= 0.11.0
openpyxl >= 3.0.0 # Excel支持
numpy >= 1.20.0
scipy >= 1.7.0
参考文档
重要说明
- 1. 用户确认是强制要求:分析后必须等待用户确认,不能直接生成
- 统一文件管理:所有输出文件保存至同一 output/{时间戳}-{文件名}/ 目录
- 高分辨率输出:以300 DPI生成PNG(适合出版物)
- 代码可追溯:生成的Python代码也保存至同一目录,供用户修改
- 学术风格:图表遵循顶级期刊标准(Nature/Science/Lancet风格)