paperplotter 0.1.4__tar.gz → 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {paperplotter-0.1.4/paperplotter.egg-info → paperplotter-0.1.6}/PKG-INFO +47 -41
- {paperplotter-0.1.4 → paperplotter-0.1.6}/README.md +46 -40
- paperplotter-0.1.6/examples/Data_Analysis_Utils/data_analysis_utils_example.png +0 -0
- paperplotter-0.1.6/examples/Data_Analysis_Utils/data_analysis_utils_example.py +60 -0
- paperplotter-0.1.6/examples/Data_Analysis_Utils/utility_functions_example.png +0 -0
- paperplotter-0.1.6/examples/Data_Analysis_Utils/utility_functions_example.py +74 -0
- paperplotter-0.1.6/examples/Domain_Specific_Plots/3d_plots_example.png +0 -0
- paperplotter-0.1.6/examples/Domain_Specific_Plots/3d_plots_example.py +78 -0
- paperplotter-0.1.6/examples/Domain_Specific_Plots/bifurcation_diagram_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Domain_Specific_Plots/bifurcation_diagram_example.py +14 -23
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Domain_Specific_Plots/concentration_map_example.py +8 -7
- paperplotter-0.1.6/examples/Domain_Specific_Plots/domain_specific_plots.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Domain_Specific_Plots/domain_specific_plots_example.py +10 -14
- paperplotter-0.1.6/examples/Domain_Specific_Plots/learning_curve_example.png +0 -0
- paperplotter-0.1.6/examples/Domain_Specific_Plots/learning_curve_example.py +79 -0
- paperplotter-0.1.6/examples/Domain_Specific_Plots/power_timeseries_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Domain_Specific_Plots/power_timeseries_example.py +15 -19
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/advanced_customization.py +5 -6
- paperplotter-0.1.6/examples/Features_Customization/advanced_customization_figure.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/cleanup_demonstration.py +4 -11
- paperplotter-0.1.6/examples/Features_Customization/cleanup_demonstration_figure.png +0 -0
- paperplotter-0.1.6/examples/Features_Customization/composite_figure.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/composite_figure_example.py +21 -14
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/error_handling_test.py +1 -1
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/feature_expansion_example.py +32 -22
- paperplotter-0.1.6/examples/Features_Customization/feature_expansion_figure.png +0 -0
- paperplotter-0.1.6/examples/Features_Customization/fig_annotation_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/fig_annotation_example.py +10 -10
- paperplotter-0.1.6/examples/Features_Customization/fig_text_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/fig_text_example.py +11 -11
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/global_controls_example.py +4 -10
- paperplotter-0.1.6/examples/Features_Customization/global_controls_figure.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/heatmap_colorbar_example.py +4 -10
- paperplotter-0.1.6/examples/Features_Customization/heatmap_default_figure.png +0 -0
- paperplotter-0.1.6/examples/Features_Customization/heatmap_shared_colorbar_figure.png +0 -0
- paperplotter-0.1.6/examples/Features_Customization/highlighting_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/highlighting_example.py +7 -9
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/multi_plot_grid.py +19 -23
- paperplotter-0.1.6/examples/Features_Customization/multi_plot_grid_figure.png +0 -0
- paperplotter-0.1.6/examples/Features_Customization/statistical_plots_example.png +0 -0
- paperplotter-0.1.6/examples/Features_Customization/statistical_plots_example.py +56 -0
- paperplotter-0.1.6/examples/Features_Customization/zoom_inset_example.png +0 -0
- paperplotter-0.1.6/examples/Features_Customization/zoom_inset_example.py +74 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Layout/advanced_layout_example.py +12 -12
- paperplotter-0.1.6/examples/Layout/advanced_layout_figure.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Layout/aspect_ratio_example.py +10 -11
- paperplotter-0.1.6/examples/Layout/aspect_ratio_mosaic.png +0 -0
- paperplotter-0.1.6/examples/Layout/aspect_ratio_simple_grid.png +0 -0
- paperplotter-0.1.6/examples/Layout/block_span_example.py +90 -0
- paperplotter-0.1.6/examples/Layout/block_span_figure.png +0 -0
- paperplotter-0.1.6/examples/Layout/declarative_nested_layout.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Layout/declarative_nested_layout_example.py +12 -12
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Layout/row_span_example.py +13 -13
- paperplotter-0.1.6/examples/Layout/row_span_figure.png +0 -0
- paperplotter-0.1.6/examples/Layout/twinx_chaining_example.png +0 -0
- paperplotter-0.1.6/examples/Layout/twinx_chaining_example.py +61 -0
- paperplotter-0.1.6/examples/Styles_Aesthetics/aesthetic_and_processing_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Styles_Aesthetics/aesthetic_and_processing_example.py +21 -24
- paperplotter-0.1.6/examples/Styles_Aesthetics/statistical_annotation_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Styles_Aesthetics/statistical_annotation_example.py +18 -17
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Styles_Aesthetics/style_gallery_example.py +6 -8
- paperplotter-0.1.6/examples/Styles_Aesthetics/style_gallery_flat.png +0 -0
- paperplotter-0.1.6/examples/Styles_Aesthetics/style_gallery_nord.png +0 -0
- paperplotter-0.1.6/examples/Styles_Aesthetics/style_gallery_presentation.png +0 -0
- paperplotter-0.1.6/examples/Styles_Aesthetics/style_gallery_publication.png +0 -0
- paperplotter-0.1.6/examples/Styles_Aesthetics/style_gallery_solarized_light.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/__init__.py +30 -30
- paperplotter-0.1.6/paperplot/core.py +481 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/exceptions.py +16 -7
- paperplotter-0.1.6/paperplot/mixins/analysis_plots.py +120 -0
- paperplotter-0.1.6/paperplot/mixins/domain.py +336 -0
- paperplotter-0.1.6/paperplot/mixins/generic.py +259 -0
- paperplotter-0.1.6/paperplot/mixins/ml_plots.py +64 -0
- paperplotter-0.1.6/paperplot/mixins/modifiers.py +954 -0
- paperplotter-0.1.6/paperplot/mixins/stats_modifiers.py +200 -0
- paperplotter-0.1.6/paperplot/mixins/stats_plots.py +118 -0
- paperplotter-0.1.6/paperplot/mixins/three_d_plots.py +112 -0
- paperplotter-0.1.6/paperplot/utils.py +134 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6/paperplotter.egg-info}/PKG-INFO +47 -41
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplotter.egg-info/SOURCES.txt +16 -1
- {paperplotter-0.1.4 → paperplotter-0.1.6}/pyproject.toml +1 -1
- paperplotter-0.1.6/tests/test_stats_modifiers.py +30 -0
- paperplotter-0.1.6/tests/testbug.py +30 -0
- paperplotter-0.1.4/examples/Data_Analysis_Utils/data_analysis_utils_example.png +0 -0
- paperplotter-0.1.4/examples/Data_Analysis_Utils/data_analysis_utils_example.py +0 -81
- paperplotter-0.1.4/examples/Data_Analysis_Utils/utility_functions_example.png +0 -0
- paperplotter-0.1.4/examples/Data_Analysis_Utils/utility_functions_example.py +0 -82
- paperplotter-0.1.4/examples/Domain_Specific_Plots/bifurcation_diagram_example.png +0 -0
- paperplotter-0.1.4/examples/Domain_Specific_Plots/domain_specific_plots.png +0 -0
- paperplotter-0.1.4/examples/Domain_Specific_Plots/learning_curve_example.png +0 -0
- paperplotter-0.1.4/examples/Domain_Specific_Plots/learning_curve_example.py +0 -86
- paperplotter-0.1.4/examples/Domain_Specific_Plots/power_timeseries_example.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/advanced_customization_figure.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/cleanup_demonstration_figure.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/composite_figure.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/feature_expansion_figure.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/fig_annotation_example.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/fig_text_example.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/global_controls_figure.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/heatmap_default_figure.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/heatmap_shared_colorbar_figure.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/highlighting_example.png +0 -0
- paperplotter-0.1.4/examples/Features_Customization/multi_plot_grid_figure.png +0 -0
- paperplotter-0.1.4/examples/Layout/advanced_layout_figure.png +0 -0
- paperplotter-0.1.4/examples/Layout/aspect_ratio_mosaic.png +0 -0
- paperplotter-0.1.4/examples/Layout/aspect_ratio_simple_grid.png +0 -0
- paperplotter-0.1.4/examples/Layout/block_span_example.py +0 -64
- paperplotter-0.1.4/examples/Layout/block_span_figure.png +0 -0
- paperplotter-0.1.4/examples/Layout/declarative_nested_layout.png +0 -0
- paperplotter-0.1.4/examples/Layout/row_span_figure.png +0 -0
- paperplotter-0.1.4/examples/Styles_Aesthetics/aesthetic_and_processing_example.png +0 -0
- paperplotter-0.1.4/examples/Styles_Aesthetics/statistical_annotation_example.png +0 -0
- paperplotter-0.1.4/examples/Styles_Aesthetics/style_gallery_flat.png +0 -0
- paperplotter-0.1.4/examples/Styles_Aesthetics/style_gallery_nord.png +0 -0
- paperplotter-0.1.4/examples/Styles_Aesthetics/style_gallery_presentation.png +0 -0
- paperplotter-0.1.4/examples/Styles_Aesthetics/style_gallery_publication.png +0 -0
- paperplotter-0.1.4/examples/Styles_Aesthetics/style_gallery_solarized_light.png +0 -0
- paperplotter-0.1.4/paperplot/core.py +0 -254
- paperplotter-0.1.4/paperplot/mixins/domain.py +0 -331
- paperplotter-0.1.4/paperplot/mixins/generic.py +0 -95
- paperplotter-0.1.4/paperplot/mixins/modifiers.py +0 -504
- paperplotter-0.1.4/paperplot/utils.py +0 -510
- {paperplotter-0.1.4 → paperplotter-0.1.6}/LICENSE +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/MANIFEST.in +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Domain_Specific_Plots/concentration_map_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Domain_Specific_Plots/phasor_diagram_example.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Domain_Specific_Plots/phasor_diagram_example.py +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/examples/Features_Customization/resources/placeholder_image.png +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/mixins/__init__.py +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/styles/flat.mplstyle +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/styles/nord.mplstyle +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/styles/presentation.mplstyle +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/styles/publication.mplstyle +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplot/styles/solarized_light.mplstyle +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplotter.egg-info/dependency_links.txt +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplotter.egg-info/requires.txt +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/paperplotter.egg-info/top_level.txt +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/setup.cfg +0 -0
- {paperplotter-0.1.4 → paperplotter-0.1.6}/tests/test_plotter.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: paperplotter
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: 一个为科研论文设计的声明式 Matplotlib 封装库,让复杂图表的创建变得简单直观。
|
|
5
5
|
Author-email: VerNe <yuu_seeing@foxmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -33,13 +33,15 @@ Dynamic: license-file
|
|
|
33
33
|
|
|
34
34
|
## 核心理念与特性
|
|
35
35
|
|
|
36
|
-
* **🎨 声明式链式调用**: 像写句子一样构建你的图表,例如 `plotter.add_line(...).set_title(...).set_xlabel(...)
|
|
36
|
+
* **🎨 声明式链式调用**: 像写句子一样构建你的图表,例如 `plotter.add_line(...).set_title(...).set_xlabel(...)`。绘图后,后续修饰器会自动作用于最后一个活动的子图,无需重复指定目标。
|
|
37
37
|
* **🏷️ 基于标签的控制**: 给每个子图一个独一无二的 `tag`,之后就可以随时通过 `tag` 对其进行任何修改,告别混乱的 `axes[i][j]` 索引。
|
|
38
38
|
* **🧩 强大的布局系统**: 无论是简单的 `(行, 列)` 网格,还是使用 `mosaic` 实现的跨行跨列复杂布局,都能轻松定义。
|
|
39
39
|
* **🧱 声明式嵌套布局**: 通过一个字典即可一次性定义包含子网格的复杂层级布局,并使用 `'容器.子图'` 这样的直观路径进行引用,完美实现“图中图”。
|
|
40
|
-
* **📐
|
|
41
|
-
* **✨
|
|
40
|
+
* **📐 数据驱动的尺寸控制**: 除了传统的 `figsize`,还可以通过 `subplot_aspect` 指定子图单元格的宽高比,让 `PaperPlot` 自动计算最合适的画布尺寸,确保图表比例的专业性。
|
|
41
|
+
* **✨ 内置科研主题与调色板**: 提供多种专业美观的内置样式(如 `publication`)和调色板(如 `seaborn_deep`),一键切换图表风格和颜色方案,保证全局一致性。
|
|
42
42
|
* **🌐 全局图层级标注**: 提供了在整个画布(Figure)上添加文本、线条、方框和标签的 API,非常适合添加全局注释或高亮一组图表。
|
|
43
|
+
* **🔢 子图自动编号**: 通过 `add_subplot_labels()` 方法,可以一键为所有子图添加 `(a)`, `(b)`, `(c)`... 等学术论文中常见的编号,并支持高度定制化。
|
|
44
|
+
* **🔗 优雅的双Y轴(Twin-Axis)**: 彻底解决了 Matplotlib 双Y轴操作繁琐的问题。通过 `add_twinx()` 进入孪生轴上下文,然后可以继续使用链式调用进行绘图和修饰,最后通过 `target_primary()` 切回主轴。
|
|
43
45
|
* **🔬 丰富的领域专用图表**: 内置了科研中常用的图表类型,如光谱图、混淆矩阵、ROC 曲线、学习曲线、分岔图、相量图等。
|
|
44
46
|
* **🔧 智能美化工具**: `cleanup()` 方法可以智能地共享坐标轴、对齐标签;`cleanup_heatmaps()` 可以为多个热图创建共享的颜色条。
|
|
45
47
|
|
|
@@ -68,30 +70,31 @@ df_scatter = pd.DataFrame({
|
|
|
68
70
|
'y': np.random.rand(50) * 10
|
|
69
71
|
})
|
|
70
72
|
|
|
71
|
-
# 2. 初始化 Plotter
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
#
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
73
|
+
# 2. 初始化 Plotter 并通过链式调用绘图和修饰
|
|
74
|
+
(
|
|
75
|
+
pp.Plotter(layout=(1, 2), figsize=(10, 4))
|
|
76
|
+
|
|
77
|
+
# --- 绘制并修饰左图 ---
|
|
78
|
+
# add_line 将 'time_series' 设为活动tag
|
|
79
|
+
.add_line(data=df_line, x='time', y='signal', tag='time_series')
|
|
80
|
+
# 后续的修饰器会自动应用到 'time_series' 上
|
|
81
|
+
.set_title('Time Series Data')
|
|
82
|
+
.set_xlabel('Time (s)')
|
|
83
|
+
.set_ylabel('Signal')
|
|
84
|
+
|
|
85
|
+
# --- 绘制并修饰右图 ---
|
|
86
|
+
# add_scatter 将 'scatter_plot' 设为新的活动tag
|
|
87
|
+
.add_scatter(data=df_scatter, x='x', y='y', tag='scatter_plot')
|
|
88
|
+
# 后续的修饰器会自动应用到 'scatter_plot' 上
|
|
89
|
+
.set_title('Scatter Plot')
|
|
90
|
+
.set_xlabel('X Value')
|
|
91
|
+
.set_ylabel('Y Value')
|
|
92
|
+
|
|
93
|
+
# --- 保存图像 ---
|
|
94
|
+
.save("quick_start_figure.png")
|
|
95
|
+
)
|
|
92
96
|
```
|
|
93
97
|
|
|
94
|
-
|
|
95
98
|
## 通过示例学习 (Learn from Examples)
|
|
96
99
|
|
|
97
100
|
掌握 `PaperPlot` 最好的方法就是探索我们提供的丰富示例。每个示例都专注于一个核心功能,并附有详细的代码和注释。
|
|
@@ -101,56 +104,59 @@ plotter.save("quick_start_figure.png")
|
|
|
101
104
|
| 示例 | 描述 | 关键功能 |
|
|
102
105
|
| :--- | :--- | :--- |
|
|
103
106
|
| **声明式嵌套布局**<br/> `Layout/declarative_nested_layout_example.py` | 使用字典来声明式地定义一个包含子网格的复杂、多层级布局,实现“图中图”的效果。 | `layout={...}`<br/> `tag='容器.子图'` |
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
| **固定子图宽高比**<br/> `Layout/aspect_ratio_example.py` |
|
|
107
|
+
| **高级布局 (跨列)**<br/> `Layout/advanced_layout_example.py` | 展示如何使用列表定义一个跨列的复杂布局。 | `layout=[['A', 'B', 'B'], ...]`<br/>`get_ax_by_name()` |
|
|
108
|
+
| **高级布局 (跨行)**<br/> `Layout/row_span_example.py` | 创建一个图表,其中某个子图跨越多行。 | `layout=[['A', 'B'], ['A', 'C']]` |
|
|
109
|
+
| **高级布局 (块跨越)**<br/> `Layout/block_span_example.py` | 创建一个图表,其中某个子图同时跨越多行和多列。 | `layout=[['A', 'A', 'B'], ['A', 'A', 'C']]` |
|
|
110
|
+
| **固定子图宽高比**<br/> `Layout/aspect_ratio_example.py` | 通过 `subplot_aspect` 保证每个子图单元格的宽高比,Plotter 会自动计算画布大小,无需指定 `figsize`。 | `subplot_aspect=(16, 9)` |
|
|
111
|
+
| **组合图与内嵌图**<br/> `Features_Customization/composite_figure_example.py` | 创建一个 L 型的复杂图表(使用 `.` 作为空白占位符),并在其中一个子图内部嵌入一张图片。 | `layout=[['A', 'A'], ['B', '.']]`<br/>`add_inset_image()` |
|
|
108
112
|
|
|
109
113
|
### 功能与定制化 (Features & Customization)
|
|
110
114
|
|
|
111
115
|
| 示例 | 描述 | 关键功能 |
|
|
112
116
|
| :--- | :--- | :--- |
|
|
113
117
|
| **多图网格**<br/> `Features_Customization/multi_plot_grid.py` | 在一个网格中通过链式调用混合绘制不同类型的图表。 | `plotter.add_...().add_...()` |
|
|
114
|
-
|
|
|
115
|
-
|
|
|
118
|
+
| **双Y轴 (Twin-Axis)**<br/> `Features_Customization/feature_expansion_example.py` | 演示如何通过上下文切换,流畅地在主轴和孪生轴上进行绘图和修饰。 | `add_twinx()`, `target_primary()`, `target_twin()` |
|
|
119
|
+
| **缩放嵌入图 (Zoom Inset)**<br/> `Features_Customization/zoom_inset_example.py` | 在主图上创建一个放大特定区域的嵌入式子图,并自动添加连接线。 | `add_zoom_inset()` |
|
|
116
120
|
| **共享颜色条**<br/> `Features_Customization/heatmap_colorbar_example.py` | 为多个热图创建一个共享的、能反映全局数据范围的颜色条。 | `add_heatmap(cbar=False)`, `cleanup_heatmaps()` |
|
|
121
|
+
| **高级定制**<br/> `Features_Customization/advanced_customization.py` | 演示如何使用 `get_ax()` "逃生舱口" 来获取原生的 Matplotlib `Axes` 对象,并添加任意 `Patch`(如椭圆)。 | `get_ax()`, `add_patch()` |
|
|
122
|
+
| **全局控制**<br/> `Features_Customization/global_controls_example.py` | 展示如何设置全局标题 (`suptitle`) 和创建全局图例。 | `set_suptitle()`, `add_global_legend()` |
|
|
117
123
|
| **智能清理**<br/> `Features_Customization/cleanup_demonstration.py` | 演示 `cleanup()` 函数如何动态地为指定行/列的子图共享 X/Y 轴,并自动隐藏多余的刻度标签。 | `cleanup(auto_share=True)` |
|
|
118
|
-
| **组合图与内嵌图**<br/> `Features_Customization/composite_figure_example.py` | 创建一个 L 型的复杂图表,并在其中一个子图内部嵌入一张图片。 | `layout=[['A', 'A'], ['B', '.']]`, `add_inset_image()` |
|
|
119
|
-
| **功能扩展**<br/> `Features_Customization/feature_expansion_example.py` | 演示双Y轴 (`add_twinx`)、回归图 (`add_regplot`)、参考线 (`add_hline`) 和文本标注 (`add_text`) 等高级功能。 | `add_twinx()`, `add_regplot()`, `add_hline()`, `add_text()` |
|
|
120
124
|
| **错误处理**<br/> `Features_Customization/error_handling_test.py` | 展示 `PaperPlot` 的自定义异常,如 `DuplicateTagError`, `TagNotFoundError`, `PlottingSpaceError`。 | `try...except pp.PaperPlotError` |
|
|
121
125
|
|
|
122
126
|
### 标注与高亮 (Annotation & Highlighting)
|
|
123
127
|
|
|
124
128
|
| 示例 | 描述 | 关键功能 |
|
|
125
129
|
| :--- | :--- | :--- |
|
|
126
|
-
|
|
|
130
|
+
| **画布级标注**<br/>`Features_Customization/fig_annotation_example.py`| 演示添加跨越多个子图的画布级注解,如方框、标签和线条。| `fig_add_box()`, `fig_add_label()`, `fig_add_line()`, `fig_add_text()`|
|
|
127
131
|
| **区域高亮**<br/>`Features_Customization/highlighting_example.py` | 展示如何在子图内部高亮特定的数据区域,并为整个图表添加边框。| `add_highlight_box()`, `fig_add_boundary_box()` |
|
|
132
|
+
| **通用工具函数**<br/> `Data_Analysis_Utils/utility_functions_example.py` | 展示更多通用的修饰函数,如在高光谱上高亮特征峰和在时间序列上标记事件。 | `add_peak_highlights()`, `add_event_markers()` |
|
|
128
133
|
|
|
129
134
|
### 风格与美化 (Styles & Aesthetics)
|
|
130
135
|
|
|
131
136
|
| 示例 | 描述 | 关键功能 |
|
|
132
137
|
| :--- | :--- | :--- |
|
|
133
138
|
| **风格画廊**<br/> `Styles_Aesthetics/style_gallery_example.py` | 循环遍历所有内置的绘图风格,并为每种风格生成一个示例图。 | `Plotter(style='...')` |
|
|
134
|
-
| **统计标注**<br/> `Styles_Aesthetics/statistical_annotation_example.py` | 在箱线图上自动进行多组成对统计检验(如 t-test),并智能堆叠显著性标记。 | `add_box()`, `
|
|
135
|
-
| **美学与处理**<br/> `Styles_Aesthetics/aesthetic_and_processing_example.py` |
|
|
139
|
+
| **统计标注**<br/> `Styles_Aesthetics/statistical_annotation_example.py` | 在箱线图上自动进行多组成对统计检验(如 t-test),并智能堆叠显著性标记。 | `add_box()`, `add_pairwise_tests()` |
|
|
140
|
+
| **美学与处理**<br/> `Styles_Aesthetics/aesthetic_and_processing_example.py` | 对数据进行平滑处理或根据条件高亮特定数据点。 | `utils.moving_average()`, `add_conditional_scatter()` |
|
|
141
|
+
| **统计图组合**<br/> `Features_Customization/statistical_plots_example.py` | 演示如何组合小提琴图和蜂群图,以及在箱线图上添加统计检验。 | `add_violin()`, `add_swarm()`, `add_box()`, `add_stat_test()` |
|
|
136
142
|
|
|
137
143
|
### 领域专用图 (Domain-Specific Plots)
|
|
138
144
|
|
|
139
145
|
| 示例 | 描述 | 关键功能 |
|
|
140
146
|
| :--- | :--- | :--- |
|
|
141
147
|
| **领域专用图合集**<br/> `Domain_Specific_Plots/domain_specific_plots_example.py` | 一站式展示多种领域专用图,包括 SERS 光谱图、混淆矩阵、ROC 曲线和 PCA 散点图。 | `add_spectra()`, `add_confusion_matrix()`, `add_roc_curve()`, `add_pca_scatter()` |
|
|
142
|
-
|
|
|
148
|
+
| **3D 绘图**<br/> `Domain_Specific_Plots/3d_plots_example.py` | 展示如何创建 3D 线图和表面图。 | `ax_configs={'...': {'projection': '3d'}}`, `add_line3d()`, `add_surface()` |
|
|
149
|
+
| **学习曲线**<br/> `Domain_Specific_Plots/learning_curve_example.py` | 绘制机器学习模型的学习曲线,帮助诊断过拟合或欠拟合问题。 | `add_learning_curve()` |
|
|
143
150
|
| **SERS 浓度图**<br/> `Domain_Specific_Plots/concentration_map_example.py` | 绘制 SERS Mapping 浓度图,本质上是带有专业美化的热图。 | `add_concentration_map()` |
|
|
144
151
|
| **电力系统时间序列**<br/> `Domain_Specific_Plots/power_timeseries_example.py` | 绘制电力系统动态仿真结果,并自动标记故障、切除等事件。 | `add_power_timeseries()` |
|
|
145
152
|
| **相量图**<br/> `Domain_Specific_Plots/phasor_diagram_example.py` | 在极坐标上绘制电气工程中的相量图。 | `add_phasor_diagram()` |
|
|
146
|
-
| **分岔图**<br/> `Domain_Specific_Plots/bifurcation_diagram_example.py` | 绘制常用于非线性系统和稳定性分析的分岔图。 | `
|
|
153
|
+
| **分岔图**<br/> `Domain_Specific_Plots/bifurcation_diagram_example.py` | 绘制常用于非线性系统和稳定性分析的分岔图。 | `add_bifurcation_diagram()` |
|
|
147
154
|
|
|
148
155
|
### 数据分析工具 (Data Analysis Utils)
|
|
149
156
|
|
|
150
157
|
| 示例 | 描述 | 关键功能 |
|
|
151
158
|
| :--- | :--- | :--- |
|
|
152
|
-
| **数据分析工具集**<br/> `Data_Analysis_Utils/data_analysis_utils_example.py` |
|
|
153
|
-
| **通用工具函数**<br/> `Data_Analysis_Utils/utility_functions_example.py` | 展示更多通用的 `utils` 函数,如在高光谱上高亮特征峰 (`highlight_peaks`) 和在时间序列上标记事件 (`add_event_markers`)。 | `utils.highlight_peaks()`, `utils.add_event_markers()` |
|
|
159
|
+
| **数据分析工具集**<br/> `Data_Analysis_Utils/data_analysis_utils_example.py` | 演示如何对数据进行分布拟合和数据分箱绘图。 | `add_distribution_fit()`, `add_binned_plot()` |
|
|
154
160
|
|
|
155
161
|
---
|
|
156
162
|
|
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
|
|
10
10
|
## 核心理念与特性
|
|
11
11
|
|
|
12
|
-
* **🎨 声明式链式调用**: 像写句子一样构建你的图表,例如 `plotter.add_line(...).set_title(...).set_xlabel(...)
|
|
12
|
+
* **🎨 声明式链式调用**: 像写句子一样构建你的图表,例如 `plotter.add_line(...).set_title(...).set_xlabel(...)`。绘图后,后续修饰器会自动作用于最后一个活动的子图,无需重复指定目标。
|
|
13
13
|
* **🏷️ 基于标签的控制**: 给每个子图一个独一无二的 `tag`,之后就可以随时通过 `tag` 对其进行任何修改,告别混乱的 `axes[i][j]` 索引。
|
|
14
14
|
* **🧩 强大的布局系统**: 无论是简单的 `(行, 列)` 网格,还是使用 `mosaic` 实现的跨行跨列复杂布局,都能轻松定义。
|
|
15
15
|
* **🧱 声明式嵌套布局**: 通过一个字典即可一次性定义包含子网格的复杂层级布局,并使用 `'容器.子图'` 这样的直观路径进行引用,完美实现“图中图”。
|
|
16
|
-
* **📐
|
|
17
|
-
* **✨
|
|
16
|
+
* **📐 数据驱动的尺寸控制**: 除了传统的 `figsize`,还可以通过 `subplot_aspect` 指定子图单元格的宽高比,让 `PaperPlot` 自动计算最合适的画布尺寸,确保图表比例的专业性。
|
|
17
|
+
* **✨ 内置科研主题与调色板**: 提供多种专业美观的内置样式(如 `publication`)和调色板(如 `seaborn_deep`),一键切换图表风格和颜色方案,保证全局一致性。
|
|
18
18
|
* **🌐 全局图层级标注**: 提供了在整个画布(Figure)上添加文本、线条、方框和标签的 API,非常适合添加全局注释或高亮一组图表。
|
|
19
|
+
* **🔢 子图自动编号**: 通过 `add_subplot_labels()` 方法,可以一键为所有子图添加 `(a)`, `(b)`, `(c)`... 等学术论文中常见的编号,并支持高度定制化。
|
|
20
|
+
* **🔗 优雅的双Y轴(Twin-Axis)**: 彻底解决了 Matplotlib 双Y轴操作繁琐的问题。通过 `add_twinx()` 进入孪生轴上下文,然后可以继续使用链式调用进行绘图和修饰,最后通过 `target_primary()` 切回主轴。
|
|
19
21
|
* **🔬 丰富的领域专用图表**: 内置了科研中常用的图表类型,如光谱图、混淆矩阵、ROC 曲线、学习曲线、分岔图、相量图等。
|
|
20
22
|
* **🔧 智能美化工具**: `cleanup()` 方法可以智能地共享坐标轴、对齐标签;`cleanup_heatmaps()` 可以为多个热图创建共享的颜色条。
|
|
21
23
|
|
|
@@ -44,30 +46,31 @@ df_scatter = pd.DataFrame({
|
|
|
44
46
|
'y': np.random.rand(50) * 10
|
|
45
47
|
})
|
|
46
48
|
|
|
47
|
-
# 2. 初始化 Plotter
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
# 2. 初始化 Plotter 并通过链式调用绘图和修饰
|
|
50
|
+
(
|
|
51
|
+
pp.Plotter(layout=(1, 2), figsize=(10, 4))
|
|
52
|
+
|
|
53
|
+
# --- 绘制并修饰左图 ---
|
|
54
|
+
# add_line 将 'time_series' 设为活动tag
|
|
55
|
+
.add_line(data=df_line, x='time', y='signal', tag='time_series')
|
|
56
|
+
# 后续的修饰器会自动应用到 'time_series' 上
|
|
57
|
+
.set_title('Time Series Data')
|
|
58
|
+
.set_xlabel('Time (s)')
|
|
59
|
+
.set_ylabel('Signal')
|
|
60
|
+
|
|
61
|
+
# --- 绘制并修饰右图 ---
|
|
62
|
+
# add_scatter 将 'scatter_plot' 设为新的活动tag
|
|
63
|
+
.add_scatter(data=df_scatter, x='x', y='y', tag='scatter_plot')
|
|
64
|
+
# 后续的修饰器会自动应用到 'scatter_plot' 上
|
|
65
|
+
.set_title('Scatter Plot')
|
|
66
|
+
.set_xlabel('X Value')
|
|
67
|
+
.set_ylabel('Y Value')
|
|
68
|
+
|
|
69
|
+
# --- 保存图像 ---
|
|
70
|
+
.save("quick_start_figure.png")
|
|
71
|
+
)
|
|
68
72
|
```
|
|
69
73
|
|
|
70
|
-
|
|
71
74
|
## 通过示例学习 (Learn from Examples)
|
|
72
75
|
|
|
73
76
|
掌握 `PaperPlot` 最好的方法就是探索我们提供的丰富示例。每个示例都专注于一个核心功能,并附有详细的代码和注释。
|
|
@@ -77,56 +80,59 @@ plotter.save("quick_start_figure.png")
|
|
|
77
80
|
| 示例 | 描述 | 关键功能 |
|
|
78
81
|
| :--- | :--- | :--- |
|
|
79
82
|
| **声明式嵌套布局**<br/> `Layout/declarative_nested_layout_example.py` | 使用字典来声明式地定义一个包含子网格的复杂、多层级布局,实现“图中图”的效果。 | `layout={...}`<br/> `tag='容器.子图'` |
|
|
80
|
-
|
|
|
81
|
-
|
|
|
82
|
-
|
|
|
83
|
-
| **固定子图宽高比**<br/> `Layout/aspect_ratio_example.py` |
|
|
83
|
+
| **高级布局 (跨列)**<br/> `Layout/advanced_layout_example.py` | 展示如何使用列表定义一个跨列的复杂布局。 | `layout=[['A', 'B', 'B'], ...]`<br/>`get_ax_by_name()` |
|
|
84
|
+
| **高级布局 (跨行)**<br/> `Layout/row_span_example.py` | 创建一个图表,其中某个子图跨越多行。 | `layout=[['A', 'B'], ['A', 'C']]` |
|
|
85
|
+
| **高级布局 (块跨越)**<br/> `Layout/block_span_example.py` | 创建一个图表,其中某个子图同时跨越多行和多列。 | `layout=[['A', 'A', 'B'], ['A', 'A', 'C']]` |
|
|
86
|
+
| **固定子图宽高比**<br/> `Layout/aspect_ratio_example.py` | 通过 `subplot_aspect` 保证每个子图单元格的宽高比,Plotter 会自动计算画布大小,无需指定 `figsize`。 | `subplot_aspect=(16, 9)` |
|
|
87
|
+
| **组合图与内嵌图**<br/> `Features_Customization/composite_figure_example.py` | 创建一个 L 型的复杂图表(使用 `.` 作为空白占位符),并在其中一个子图内部嵌入一张图片。 | `layout=[['A', 'A'], ['B', '.']]`<br/>`add_inset_image()` |
|
|
84
88
|
|
|
85
89
|
### 功能与定制化 (Features & Customization)
|
|
86
90
|
|
|
87
91
|
| 示例 | 描述 | 关键功能 |
|
|
88
92
|
| :--- | :--- | :--- |
|
|
89
93
|
| **多图网格**<br/> `Features_Customization/multi_plot_grid.py` | 在一个网格中通过链式调用混合绘制不同类型的图表。 | `plotter.add_...().add_...()` |
|
|
90
|
-
|
|
|
91
|
-
|
|
|
94
|
+
| **双Y轴 (Twin-Axis)**<br/> `Features_Customization/feature_expansion_example.py` | 演示如何通过上下文切换,流畅地在主轴和孪生轴上进行绘图和修饰。 | `add_twinx()`, `target_primary()`, `target_twin()` |
|
|
95
|
+
| **缩放嵌入图 (Zoom Inset)**<br/> `Features_Customization/zoom_inset_example.py` | 在主图上创建一个放大特定区域的嵌入式子图,并自动添加连接线。 | `add_zoom_inset()` |
|
|
92
96
|
| **共享颜色条**<br/> `Features_Customization/heatmap_colorbar_example.py` | 为多个热图创建一个共享的、能反映全局数据范围的颜色条。 | `add_heatmap(cbar=False)`, `cleanup_heatmaps()` |
|
|
97
|
+
| **高级定制**<br/> `Features_Customization/advanced_customization.py` | 演示如何使用 `get_ax()` "逃生舱口" 来获取原生的 Matplotlib `Axes` 对象,并添加任意 `Patch`(如椭圆)。 | `get_ax()`, `add_patch()` |
|
|
98
|
+
| **全局控制**<br/> `Features_Customization/global_controls_example.py` | 展示如何设置全局标题 (`suptitle`) 和创建全局图例。 | `set_suptitle()`, `add_global_legend()` |
|
|
93
99
|
| **智能清理**<br/> `Features_Customization/cleanup_demonstration.py` | 演示 `cleanup()` 函数如何动态地为指定行/列的子图共享 X/Y 轴,并自动隐藏多余的刻度标签。 | `cleanup(auto_share=True)` |
|
|
94
|
-
| **组合图与内嵌图**<br/> `Features_Customization/composite_figure_example.py` | 创建一个 L 型的复杂图表,并在其中一个子图内部嵌入一张图片。 | `layout=[['A', 'A'], ['B', '.']]`, `add_inset_image()` |
|
|
95
|
-
| **功能扩展**<br/> `Features_Customization/feature_expansion_example.py` | 演示双Y轴 (`add_twinx`)、回归图 (`add_regplot`)、参考线 (`add_hline`) 和文本标注 (`add_text`) 等高级功能。 | `add_twinx()`, `add_regplot()`, `add_hline()`, `add_text()` |
|
|
96
100
|
| **错误处理**<br/> `Features_Customization/error_handling_test.py` | 展示 `PaperPlot` 的自定义异常,如 `DuplicateTagError`, `TagNotFoundError`, `PlottingSpaceError`。 | `try...except pp.PaperPlotError` |
|
|
97
101
|
|
|
98
102
|
### 标注与高亮 (Annotation & Highlighting)
|
|
99
103
|
|
|
100
104
|
| 示例 | 描述 | 关键功能 |
|
|
101
105
|
| :--- | :--- | :--- |
|
|
102
|
-
|
|
|
106
|
+
| **画布级标注**<br/>`Features_Customization/fig_annotation_example.py`| 演示添加跨越多个子图的画布级注解,如方框、标签和线条。| `fig_add_box()`, `fig_add_label()`, `fig_add_line()`, `fig_add_text()`|
|
|
103
107
|
| **区域高亮**<br/>`Features_Customization/highlighting_example.py` | 展示如何在子图内部高亮特定的数据区域,并为整个图表添加边框。| `add_highlight_box()`, `fig_add_boundary_box()` |
|
|
108
|
+
| **通用工具函数**<br/> `Data_Analysis_Utils/utility_functions_example.py` | 展示更多通用的修饰函数,如在高光谱上高亮特征峰和在时间序列上标记事件。 | `add_peak_highlights()`, `add_event_markers()` |
|
|
104
109
|
|
|
105
110
|
### 风格与美化 (Styles & Aesthetics)
|
|
106
111
|
|
|
107
112
|
| 示例 | 描述 | 关键功能 |
|
|
108
113
|
| :--- | :--- | :--- |
|
|
109
114
|
| **风格画廊**<br/> `Styles_Aesthetics/style_gallery_example.py` | 循环遍历所有内置的绘图风格,并为每种风格生成一个示例图。 | `Plotter(style='...')` |
|
|
110
|
-
| **统计标注**<br/> `Styles_Aesthetics/statistical_annotation_example.py` | 在箱线图上自动进行多组成对统计检验(如 t-test),并智能堆叠显著性标记。 | `add_box()`, `
|
|
111
|
-
| **美学与处理**<br/> `Styles_Aesthetics/aesthetic_and_processing_example.py` |
|
|
115
|
+
| **统计标注**<br/> `Styles_Aesthetics/statistical_annotation_example.py` | 在箱线图上自动进行多组成对统计检验(如 t-test),并智能堆叠显著性标记。 | `add_box()`, `add_pairwise_tests()` |
|
|
116
|
+
| **美学与处理**<br/> `Styles_Aesthetics/aesthetic_and_processing_example.py` | 对数据进行平滑处理或根据条件高亮特定数据点。 | `utils.moving_average()`, `add_conditional_scatter()` |
|
|
117
|
+
| **统计图组合**<br/> `Features_Customization/statistical_plots_example.py` | 演示如何组合小提琴图和蜂群图,以及在箱线图上添加统计检验。 | `add_violin()`, `add_swarm()`, `add_box()`, `add_stat_test()` |
|
|
112
118
|
|
|
113
119
|
### 领域专用图 (Domain-Specific Plots)
|
|
114
120
|
|
|
115
121
|
| 示例 | 描述 | 关键功能 |
|
|
116
122
|
| :--- | :--- | :--- |
|
|
117
123
|
| **领域专用图合集**<br/> `Domain_Specific_Plots/domain_specific_plots_example.py` | 一站式展示多种领域专用图,包括 SERS 光谱图、混淆矩阵、ROC 曲线和 PCA 散点图。 | `add_spectra()`, `add_confusion_matrix()`, `add_roc_curve()`, `add_pca_scatter()` |
|
|
118
|
-
|
|
|
124
|
+
| **3D 绘图**<br/> `Domain_Specific_Plots/3d_plots_example.py` | 展示如何创建 3D 线图和表面图。 | `ax_configs={'...': {'projection': '3d'}}`, `add_line3d()`, `add_surface()` |
|
|
125
|
+
| **学习曲线**<br/> `Domain_Specific_Plots/learning_curve_example.py` | 绘制机器学习模型的学习曲线,帮助诊断过拟合或欠拟合问题。 | `add_learning_curve()` |
|
|
119
126
|
| **SERS 浓度图**<br/> `Domain_Specific_Plots/concentration_map_example.py` | 绘制 SERS Mapping 浓度图,本质上是带有专业美化的热图。 | `add_concentration_map()` |
|
|
120
127
|
| **电力系统时间序列**<br/> `Domain_Specific_Plots/power_timeseries_example.py` | 绘制电力系统动态仿真结果,并自动标记故障、切除等事件。 | `add_power_timeseries()` |
|
|
121
128
|
| **相量图**<br/> `Domain_Specific_Plots/phasor_diagram_example.py` | 在极坐标上绘制电气工程中的相量图。 | `add_phasor_diagram()` |
|
|
122
|
-
| **分岔图**<br/> `Domain_Specific_Plots/bifurcation_diagram_example.py` | 绘制常用于非线性系统和稳定性分析的分岔图。 | `
|
|
129
|
+
| **分岔图**<br/> `Domain_Specific_Plots/bifurcation_diagram_example.py` | 绘制常用于非线性系统和稳定性分析的分岔图。 | `add_bifurcation_diagram()` |
|
|
123
130
|
|
|
124
131
|
### 数据分析工具 (Data Analysis Utils)
|
|
125
132
|
|
|
126
133
|
| 示例 | 描述 | 关键功能 |
|
|
127
134
|
| :--- | :--- | :--- |
|
|
128
|
-
| **数据分析工具集**<br/> `Data_Analysis_Utils/data_analysis_utils_example.py` |
|
|
129
|
-
| **通用工具函数**<br/> `Data_Analysis_Utils/utility_functions_example.py` | 展示更多通用的 `utils` 函数,如在高光谱上高亮特征峰 (`highlight_peaks`) 和在时间序列上标记事件 (`add_event_markers`)。 | `utils.highlight_peaks()`, `utils.add_event_markers()` |
|
|
135
|
+
| **数据分析工具集**<br/> `Data_Analysis_Utils/data_analysis_utils_example.py` | 演示如何对数据进行分布拟合和数据分箱绘图。 | `add_distribution_fit()`, `add_binned_plot()` |
|
|
130
136
|
|
|
131
137
|
---
|
|
132
138
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# examples/data_analysis_utils_example.py
|
|
2
|
+
|
|
3
|
+
import paperplot as pp
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import numpy as np
|
|
6
|
+
import matplotlib.pyplot as plt
|
|
7
|
+
|
|
8
|
+
print(f"--- Running Example: {__file__} ---")
|
|
9
|
+
|
|
10
|
+
# --- 1. 准备数据 ---
|
|
11
|
+
# 分布拟合示例数据
|
|
12
|
+
np.random.seed(42)
|
|
13
|
+
normal_data = np.random.normal(loc=0, scale=1, size=1000)
|
|
14
|
+
df_dist = pd.DataFrame({'value': normal_data})
|
|
15
|
+
|
|
16
|
+
# 数据分箱示例数据
|
|
17
|
+
x_bin = np.linspace(0, 10, 200)
|
|
18
|
+
y_bin = 2 * x_bin + np.random.normal(loc=0, scale=2, size=200)
|
|
19
|
+
df_bin = pd.DataFrame({'x': x_bin, 'y': y_bin})
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# --- 2. 创建绘图 ---
|
|
23
|
+
try:
|
|
24
|
+
# 使用新的 API 进行绘图和修饰
|
|
25
|
+
(
|
|
26
|
+
pp.Plotter(layout=(1, 2), figsize=(12, 5))
|
|
27
|
+
.set_suptitle("Data Analysis Utilities (New API)", fontsize=16, weight='bold')
|
|
28
|
+
|
|
29
|
+
# --- 左图: 分布拟合 ---
|
|
30
|
+
.add_hist(data=df_dist, x='value', tag='dist', bins=30, density=True, alpha=0.6, color='skyblue', label='Data Histogram')
|
|
31
|
+
.add_distribution_fit(data=df_dist, x='value', dist_name='norm', color='red', linestyle='--', lw=2, tag='dist')
|
|
32
|
+
.set_title("add_distribution_fit() Example", tag='dist')
|
|
33
|
+
.set_xlabel("Value", tag='dist')
|
|
34
|
+
.set_ylabel("Density", tag='dist')
|
|
35
|
+
.set_legend(tag='dist')
|
|
36
|
+
|
|
37
|
+
# --- 右图: 数据分箱 ---
|
|
38
|
+
.add_scatter(data=df_bin, x='x', y='y', tag='bin', alpha=0.3, label='Raw Data')
|
|
39
|
+
.add_binned_plot(data=df_bin, x='x', y='y', bins=5, plot_type='errorbar',
|
|
40
|
+
color='green', fmt='-o', capsize=5, label='Binned Data (Mean ± Std)', tag='bin')
|
|
41
|
+
.set_title("add_binned_plot() Example", tag='bin')
|
|
42
|
+
.set_xlabel("X Value", tag='bin')
|
|
43
|
+
.set_ylabel("Y Value", tag='bin')
|
|
44
|
+
.set_legend(tag='bin')
|
|
45
|
+
|
|
46
|
+
# --- 清理和保存 ---
|
|
47
|
+
.cleanup()
|
|
48
|
+
.save("data_analysis_utils_example.png")
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
except Exception as e:
|
|
52
|
+
print(f"An unexpected error occurred: {e}")
|
|
53
|
+
# 在调试时,取消下面的注释可以打印更详细的错误信息
|
|
54
|
+
# import traceback
|
|
55
|
+
# traceback.print_exc()
|
|
56
|
+
finally:
|
|
57
|
+
plt.close('all')
|
|
58
|
+
|
|
59
|
+
print(f"\n--- Finished Example: {__file__} ---")
|
|
60
|
+
print("A new file 'data_analysis_utils_example.png' was generated with the new API.")
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# examples/utility_functions_example.py
|
|
2
|
+
|
|
3
|
+
import paperplot as pp
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import numpy as np
|
|
6
|
+
import matplotlib.pyplot as plt
|
|
7
|
+
|
|
8
|
+
print(f"--- Running Example: {__file__} ---")
|
|
9
|
+
|
|
10
|
+
# --- 1. 准备数据 ---
|
|
11
|
+
|
|
12
|
+
# SERS 光谱数据
|
|
13
|
+
x_spec = np.linspace(400, 1800, 1000)
|
|
14
|
+
y_spec = (0.8 * np.exp(-((x_spec - 600)**2) / (2 * 30**2)) +
|
|
15
|
+
0.6 * np.exp(-((x_spec - 1200)**2) / (2 * 50**2)) +
|
|
16
|
+
np.random.rand(1000) * 0.1)
|
|
17
|
+
spectra_df = pd.DataFrame({'wavenumber': x_spec, 'intensity': y_spec})
|
|
18
|
+
peaks_to_highlight = [600, 1200]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# 时间序列数据
|
|
22
|
+
time = np.linspace(0, 100, 200)
|
|
23
|
+
signal = np.sin(time / 10) * np.exp(time / 50) + np.random.randn(200) * 0.1
|
|
24
|
+
timeseries_df = pd.DataFrame({'time': time, 'signal': signal})
|
|
25
|
+
event_points = [25, 50, 80]
|
|
26
|
+
event_labels = ['Fault', 'Clear', 'Load Shed']
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# --- 2. 创建一个 1x2 的布局并使用新API绘图 ---
|
|
30
|
+
try:
|
|
31
|
+
(
|
|
32
|
+
pp.Plotter(layout=(1, 2), figsize=(12, 5))
|
|
33
|
+
.set_suptitle("Utility Functions Demonstration (New API)", fontsize=16, weight='bold')
|
|
34
|
+
|
|
35
|
+
# --- 左侧子图: 高亮光谱峰 ---
|
|
36
|
+
.add_line(data=spectra_df, x='wavenumber', y='intensity', tag='spectra')
|
|
37
|
+
.add_peak_highlights(
|
|
38
|
+
peaks_x=peaks_to_highlight,
|
|
39
|
+
x_col='wavenumber',
|
|
40
|
+
y_col='intensity',
|
|
41
|
+
label_positions={1200: (1250, 0.4)}, # 手动将1200峰的标签移动到右下方
|
|
42
|
+
ha='center' # 水平居中
|
|
43
|
+
)
|
|
44
|
+
.set_title('add_peak_highlights() Example')
|
|
45
|
+
.set_xlabel('Wavenumber (cm⁻¹)')
|
|
46
|
+
.set_ylabel('Intensity (a.u.)')
|
|
47
|
+
|
|
48
|
+
# --- 右侧子图: 标记时间序列事件 ---
|
|
49
|
+
.add_line(data=timeseries_df, x='time', y='signal', tag='timeseries', color='navy')
|
|
50
|
+
.add_event_markers(
|
|
51
|
+
event_dates=event_points,
|
|
52
|
+
labels=event_labels,
|
|
53
|
+
label_positions={25: (15, 2.5)} # 手动移动 'Fault' 标签
|
|
54
|
+
)
|
|
55
|
+
.set_title('add_event_markers() Example')
|
|
56
|
+
.set_xlabel('Time (s)')
|
|
57
|
+
.set_ylabel('Signal Value')
|
|
58
|
+
|
|
59
|
+
# --- 清理和保存 ---
|
|
60
|
+
.cleanup(align_labels=True)
|
|
61
|
+
.save("utility_functions_example.png")
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
except (pp.PaperPlotError, ValueError) as e:
|
|
65
|
+
print(f"\nAn error occurred:\n{e}")
|
|
66
|
+
except Exception as e:
|
|
67
|
+
print(f"An unexpected error occurred: {e}")
|
|
68
|
+
# import traceback
|
|
69
|
+
# traceback.print_exc()
|
|
70
|
+
finally:
|
|
71
|
+
plt.close('all')
|
|
72
|
+
|
|
73
|
+
print(f"\n--- Finished Example: {__file__} ---")
|
|
74
|
+
print("A new file 'utility_functions_example.png' was generated with the new API.")
|
|
Binary file
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# examples/Domain_Specific_Plots/3d_plots_example.py
|
|
2
|
+
|
|
3
|
+
import paperplot as pp
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import numpy as np
|
|
6
|
+
import matplotlib.pyplot as plt
|
|
7
|
+
|
|
8
|
+
print(f"--- Running Example: {__file__} ---")
|
|
9
|
+
|
|
10
|
+
# --- 1. 准备数据 ---
|
|
11
|
+
|
|
12
|
+
# 3D散点图数据 (Lorenz Attractor)
|
|
13
|
+
def lorenz(xyz, *, s=10, r=28, b=2.667):
|
|
14
|
+
x, y, z = xyz
|
|
15
|
+
dxdt = s * (y - x)
|
|
16
|
+
dydt = r * x - y - x * z
|
|
17
|
+
dzdt = x * y - b * z
|
|
18
|
+
return np.array([dxdt, dydt, dzdt])
|
|
19
|
+
|
|
20
|
+
dt = 0.01
|
|
21
|
+
num_steps = 10000
|
|
22
|
+
xyzs = np.empty((num_steps + 1, 3))
|
|
23
|
+
xyzs[0] = (0., 1., 1.05)
|
|
24
|
+
for i in range(num_steps):
|
|
25
|
+
xyzs[i + 1] = xyzs[i] + lorenz(xyzs[i]) * dt
|
|
26
|
+
df_lorenz = pd.DataFrame(xyzs, columns=['x', 'y', 'z'])
|
|
27
|
+
|
|
28
|
+
# 3D表面图数据
|
|
29
|
+
X = np.arange(-5, 5, 0.25)
|
|
30
|
+
Y = np.arange(-5, 5, 0.25)
|
|
31
|
+
X, Y = np.meshgrid(X, Y)
|
|
32
|
+
R = np.sqrt(X**2 + Y**2)
|
|
33
|
+
Z = np.sin(R)
|
|
34
|
+
|
|
35
|
+
# --- 2. 创建绘图 ---
|
|
36
|
+
try:
|
|
37
|
+
# 创建一个包含两个3D子图的布局
|
|
38
|
+
# 注意: 必须在 ax_configs 中指定 projection='3d'
|
|
39
|
+
(
|
|
40
|
+
pp.Plotter(
|
|
41
|
+
layout=(1, 2),
|
|
42
|
+
figsize=(14, 6),
|
|
43
|
+
ax_configs={
|
|
44
|
+
'ax00': {'projection': '3d'},
|
|
45
|
+
'ax01': {'projection': '3d'}
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
.set_suptitle("3D Plotting Demonstration", fontsize=16, weight='bold')
|
|
49
|
+
|
|
50
|
+
# --- 左图: 3D线图 ---
|
|
51
|
+
.add_line3d(data=df_lorenz, x='x', y='y', z='z', tag='lorenz', alpha=0.7)
|
|
52
|
+
.set_title("3D Line Plot (Lorenz Attractor)")
|
|
53
|
+
.set_xlabel("X Axis")
|
|
54
|
+
.set_ylabel("Y Axis")
|
|
55
|
+
.set_zlabel("Z Axis")
|
|
56
|
+
.view_init(elev=20, azim=-60) # 设置观察角度
|
|
57
|
+
|
|
58
|
+
# --- 右图: 3D表面图 ---
|
|
59
|
+
.add_surface(X=X, Y=Y, Z=Z, tag='surface', cmap='viridis')
|
|
60
|
+
.set_title("3D Surface Plot")
|
|
61
|
+
.set_xlabel("X")
|
|
62
|
+
.set_ylabel("Y")
|
|
63
|
+
.set_zlabel("Z")
|
|
64
|
+
.view_init(elev=45, azim=45)
|
|
65
|
+
|
|
66
|
+
# --- 保存 ---
|
|
67
|
+
.save("3d_plots_example.png")
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
except Exception as e:
|
|
71
|
+
print(f"An unexpected error occurred: {e}")
|
|
72
|
+
import traceback
|
|
73
|
+
traceback.print_exc()
|
|
74
|
+
finally:
|
|
75
|
+
plt.close('all')
|
|
76
|
+
|
|
77
|
+
print(f"\n--- Finished Example: {__file__} ---")
|
|
78
|
+
print("A new file '3d_plots_example.png' was generated.")
|
|
@@ -35,31 +35,22 @@ df_bifurcation = pd.DataFrame({
|
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
# --- 2. 创建绘图 ---
|
|
38
|
+
# --- 2. 创建绘图 (使用新API) ---
|
|
39
39
|
try:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
(
|
|
41
|
+
pp.Plotter(layout=(1, 1), figsize=(8, 6))
|
|
42
|
+
.add_bifurcation_diagram(
|
|
43
|
+
data=df_bifurcation,
|
|
44
|
+
x='r',
|
|
45
|
+
y='x',
|
|
46
|
+
s=0.001, # 调小点的大小以获得更好的视觉效果
|
|
47
|
+
alpha=0.2
|
|
48
|
+
)
|
|
49
|
+
.set_title('Bifurcation Diagram of the Logistic Map')
|
|
50
|
+
.set_xlabel('Parameter r')
|
|
51
|
+
.set_ylabel('State x')
|
|
52
|
+
.save("bifurcation_diagram_example.png")
|
|
52
53
|
)
|
|
53
|
-
|
|
54
|
-
# --- 3. 设置标题和标签 ---
|
|
55
|
-
# 现在 tag=1 已经被正确注册,可以安全使用
|
|
56
|
-
plotter.set_title(1, 'Bifurcation Diagram of the Logistic Map')
|
|
57
|
-
plotter.set_xlabel(1, 'Parameter r')
|
|
58
|
-
plotter.set_ylabel(1, 'State x')
|
|
59
|
-
|
|
60
|
-
# --- 4. 清理和保存 ---
|
|
61
|
-
plotter.cleanup()
|
|
62
|
-
plotter.save("bifurcation_diagram_example.png")
|
|
63
54
|
|
|
64
55
|
except Exception as e:
|
|
65
56
|
print(f"An unexpected error occurred: {e}")
|
|
@@ -28,15 +28,16 @@ df_concentration = pd.DataFrame(concentration, index=y_coords, columns=x_coords)
|
|
|
28
28
|
try:
|
|
29
29
|
plotter = pp.Plotter(layout=(1, 1), figsize=(7, 6))
|
|
30
30
|
|
|
31
|
-
# 使用新的 add_concentration_map
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
# 使用新的 add_concentration_map 方法,并链式调用 set_title
|
|
32
|
+
(
|
|
33
|
+
plotter.add_concentration_map(
|
|
34
|
+
data=df_concentration,
|
|
35
|
+
tag='sers_map',
|
|
36
|
+
cbar_kws={'label': 'Concentration (a.u.)'} # 自定义颜色条标签
|
|
37
|
+
)
|
|
38
|
+
.set_title('SERS Concentration Map Example')
|
|
36
39
|
)
|
|
37
40
|
|
|
38
|
-
# --- 3. 设置标题和标签 ---
|
|
39
|
-
plotter.set_title('sers_map', 'SERS Concentration Map Example')
|
|
40
41
|
# X, Y 轴标签已由 add_concentration_map 默认设置,但可以覆盖
|
|
41
42
|
# plotter.set_xlabel('sers_map', 'Position X (µm)')
|
|
42
43
|
# plotter.set_ylabel('sers_map', 'Position Y (µm)')
|