JX-Lab commited on
Commit
13f40af
·
verified ·
1 Parent(s): 5564aff

Add files using upload-large-folder tool

Browse files
Files changed (33) hide show
  1. 论文/figures/3_1/图3A_关系来源支持数分布.png +2 -2
  2. 论文/figures/3_1/图3B_每味中药关联化合物数长尾分布.png +2 -2
  3. 论文/figures/3_1/图3C_每个化合物关联中药数长尾分布.png +2 -2
  4. 论文/figures/3_1/图3_数据库来源与长尾分布_组图.png +3 -0
  5. 论文/figures/3_3/图X_十九种方案结构评价与综合排名.pdf +2 -2
  6. 论文/figures/3_3/图X_十九种方案结构评价与综合排名.png +2 -2
  7. 论文/figures/3_3/图X_十九种方案结构评价与综合排名.svg +1078 -0
  8. 论文/figures/3_3/图Y_吴越制表16种组合及关键格位平均效应.pdf +2 -2
  9. 论文/figures/3_3/图Y_吴越制表16种组合及关键格位平均效应.png +2 -2
  10. 论文/figures/3_3/图Y_吴越制表16种组合及关键格位平均效应.svg +792 -0
  11. 论文/figures/3_3/附图S1_十九种方案余弦距离MDS总览.pdf +2 -2
  12. 论文/figures/3_3/附图S1_十九种方案余弦距离MDS总览.png +2 -2
  13. 论文/figures/3_3/附图S1_十九种方案余弦距离MDS总览.svg +0 -0
  14. 论文/figures/3_3/附图S2_十九种方案Jaccard距离MDS总览.pdf +2 -2
  15. 论文/figures/3_3/附图S2_十九种方案Jaccard距离MDS总览.png +2 -2
  16. 论文/figures/3_3/附图S2_十九种方案Jaccard距离MDS总览.svg +0 -0
  17. 论文/figures/一致性/图4_四组表征一致性分析_拼接版.png +3 -0
  18. 论文/figures/一致性/图4_四组表征预测类别分布.pdf +2 -2
  19. 论文/figures/一致性/图4_四组表征预测类别分布.png +2 -2
  20. 论文/figures/一致性/图4_四组表征预测类别分布.svg +192 -189
  21. 论文/figures/一致性/图4_四组表征预测类别分布_数据.xlsx +0 -0
  22. 论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集.pdf +2 -2
  23. 论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集.png +2 -2
  24. 论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集.svg +321 -453
  25. 论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集_数据.xlsx +0 -0
  26. 论文/figures/一致性/图6_四组表征两两一致性热图.pdf +2 -2
  27. 论文/figures/一致性/图6_四组表征两两一致性热图.png +2 -2
  28. 论文/figures/一致性/图6_四组表征两两一致性热图.svg +0 -0
  29. 论文/figures/一致性/表12_四组表征两两及总体一致性.xlsx +0 -0
  30. 论文/script/图3_关系来源与长尾分布.py +92 -26
  31. 论文/script/图表_3_3_二十五味药精版本量化评估.py +86 -59
  32. 论文/script/拼接图4_无重叠.py +91 -0
  33. 论文/script/生成_3_5_2_一致性图表.py +81 -63
论文/figures/3_1/图3A_关系来源支持数分布.png CHANGED

Git LFS Details

  • SHA256: 5cca6b5a03f7d3c722e442ed460ebf4464e9ac41ba942b660b01be3acd6cf36f
  • Pointer size: 131 Bytes
  • Size of remote file: 133 kB

Git LFS Details

  • SHA256: 2dd2298261c68eaeda1d4aa3971d101aebc2fd04b8aadffd2ff1d8e989275d7a
  • Pointer size: 131 Bytes
  • Size of remote file: 137 kB
论文/figures/3_1/图3B_每味中药关联化合物数长尾分布.png CHANGED

Git LFS Details

  • SHA256: fe425e69182f0877be93a88a6fab91d4848ab97f38cddff39777f837757721db
  • Pointer size: 131 Bytes
  • Size of remote file: 118 kB

Git LFS Details

  • SHA256: 9daec5f259d9c5901211db474a37ea91555165dbf8ba6797a2487685fd483ebc
  • Pointer size: 131 Bytes
  • Size of remote file: 120 kB
论文/figures/3_1/图3C_每个化合物关联中药数长尾分布.png CHANGED

Git LFS Details

  • SHA256: a078a906c4bc248d9fc63da29989704b61ae85261fd9d37e79f0515471d8cb48
  • Pointer size: 131 Bytes
  • Size of remote file: 119 kB

Git LFS Details

  • SHA256: b1bed85323133c7808f44e847860b3f22a43fdbda307be3a172026ff9e816d96
  • Pointer size: 131 Bytes
  • Size of remote file: 126 kB
论文/figures/3_1/图3_数据库来源与长尾分布_组图.png ADDED

Git LFS Details

  • SHA256: 565fa8034d0dfadfea1f3a07a7828145168fb1195df62dabecfc2f11dd692e0e
  • Pointer size: 131 Bytes
  • Size of remote file: 362 kB
论文/figures/3_3/图X_十九种方案结构评价与综合排名.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:40e047b7655d846e9c3c35a83205e565111f12bdf945e0559028b3e346a44238
3
- size 408324
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:120d6385281ace26d4c4bcb6eaadd84ec531781325848453b47f4617372442e9
3
+ size 182853
论文/figures/3_3/图X_十九种方案结构评价与综合排名.png CHANGED

Git LFS Details

  • SHA256: d23ab3555d742a9fd306c060eb241e1e178f3e9a57cb5e2ab3d38ca8004e24bf
  • Pointer size: 131 Bytes
  • Size of remote file: 317 kB

Git LFS Details

  • SHA256: 0f8d573cf08b72696e95ccda10b2868b2bdeb483041c11ae93aa84474f1c7a45
  • Pointer size: 131 Bytes
  • Size of remote file: 470 kB
论文/figures/3_3/图X_十九种方案结构评价与综合排名.svg ADDED
论文/figures/3_3/图Y_吴越制表16种组合及关键格位平均效应.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:739a5e52480760826dc8f0d9357f36a086ca4af720923f1a193a3c6c9f132ce2
3
- size 299646
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b754b90c31889744bde8fe33835e66fadc1be310736b5fd87ccc4f76657ad41
3
+ size 202870
论文/figures/3_3/图Y_吴越制表16种组合及关键格位平均效应.png CHANGED

Git LFS Details

  • SHA256: 44c835425907838ad0ee277db33c0428de5c87623a78b57b682f6283d93b4239
  • Pointer size: 131 Bytes
  • Size of remote file: 256 kB

Git LFS Details

  • SHA256: 3ef8bf5d35a41128c30d3fd9b36c19e621a9020bc2b205f94426128b9b19894a
  • Pointer size: 131 Bytes
  • Size of remote file: 569 kB
论文/figures/3_3/图Y_吴越制表16种组合及关键格位平均效应.svg ADDED
论文/figures/3_3/附图S1_十九种方案余弦距离MDS总览.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9dd13c3c54a381eb40b003f33f2d84daeb5396105beb37d4430098e2a42df441
3
- size 328033
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70334d3ce6f3e19301699cfd188d93a620c57562e2ffbfa024bb5228c1a00d24
3
+ size 216380
论文/figures/3_3/附图S1_十九种方案余弦距离MDS总览.png CHANGED

Git LFS Details

  • SHA256: 69e93442f03e2011a0cb65f6fcb06e6fe0f5ca014ea8ea03233472032fd449e8
  • Pointer size: 132 Bytes
  • Size of remote file: 1.16 MB

Git LFS Details

  • SHA256: f9d53aed7d679523345e57bf38a81eb6ea7e1d33877cf34960743aa60f13f643
  • Pointer size: 132 Bytes
  • Size of remote file: 2.91 MB
论文/figures/3_3/附图S1_十九种方案余弦距离MDS总览.svg ADDED
论文/figures/3_3/附图S2_十九种方案Jaccard距离MDS总览.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d248a70f193195cbc154752bf669fb99b717bcc82fb7b250177bee52f2c4fc39
3
- size 328426
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce852b452f195c65151505dba51af4a794644b8458e42504957cf9068c5b370c
3
+ size 216708
论文/figures/3_3/附图S2_十九种方案Jaccard距离MDS总览.png CHANGED

Git LFS Details

  • SHA256: 70e5bf7177c5a92f0718991ff7b442790bb464ff7fe677580f3d86a92471fdf0
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB

Git LFS Details

  • SHA256: e24b3720b4f2e0bfae509373280fb7254c914d04cce6679992d69a488381bd26
  • Pointer size: 132 Bytes
  • Size of remote file: 2.62 MB
论文/figures/3_3/附图S2_十九种方案Jaccard距离MDS总览.svg ADDED
论文/figures/一致性/图4_四组表征一致性分析_拼接版.png ADDED

Git LFS Details

  • SHA256: 27030228b8b5dd4078ce5212303c244a76f5a0b33b6193c41bde6cd8141e6358
  • Pointer size: 132 Bytes
  • Size of remote file: 1.5 MB
论文/figures/一致性/图4_四组表征预测类别分布.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a29616c7777481b50e99789d43ece2d33f4d22218ba7a7776cf1a7509460fa23
3
- size 163403
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c38efbce973f588d30a5d3c92ecf2a9e67d06c22fb76de0e8c2bce9444a47af2
3
+ size 167869
论文/figures/一致性/图4_四组表征预测类别分布.png CHANGED

Git LFS Details

  • SHA256: 00c9fdc20ae72b74651909b17ec2d275c9f50f41de40c32140fad1a5bac4d481
  • Pointer size: 131 Bytes
  • Size of remote file: 309 kB

Git LFS Details

  • SHA256: 9a9db8622038f5490946fe198f9da38e7ea9b33a29c5c6ccc81b2cbb890a4d14
  • Pointer size: 131 Bytes
  • Size of remote file: 240 kB
论文/figures/一致性/图4_四组表征预测类别分布.svg CHANGED
论文/figures/一致性/图4_四组表征预测类别分布_数据.xlsx CHANGED
Binary files "a/\350\256\272\346\226\207/figures/\344\270\200\350\207\264\346\200\247/\345\233\2764_\345\233\233\347\273\204\350\241\250\345\276\201\351\242\204\346\265\213\347\261\273\345\210\253\345\210\206\345\270\203_\346\225\260\346\215\256.xlsx" and "b/\350\256\272\346\226\207/figures/\344\270\200\350\207\264\346\200\247/\345\233\2764_\345\233\233\347\273\204\350\241\250\345\276\201\351\242\204\346\265\213\347\261\273\345\210\253\345\210\206\345\270\203_\346\225\260\346\215\256.xlsx" differ
 
论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:54e464ff22bbf4ed6ca93b4353f95782a2eb83957506b790617e0498953a1490
3
- size 192037
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f99eb4b6e4025a6f6a19f601a22a7dd7caa049fbeec7d61c50936c6c3b36db96
3
+ size 185034
论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集.png CHANGED

Git LFS Details

  • SHA256: 7cf35e73235fae59c21064c0e29ea2439153e705c094c8eb9ad5b9615c28d402
  • Pointer size: 131 Bytes
  • Size of remote file: 420 kB

Git LFS Details

  • SHA256: ca49d5a4468f88d3c3cc8afdfc28234a8dff69fe43707049986cb84a212fcd0b
  • Pointer size: 131 Bytes
  • Size of remote file: 181 kB
论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集.svg CHANGED
论文/figures/一致性/图5_四组表征候选中药归属预测的严格交集_数据.xlsx CHANGED
Binary files "a/\350\256\272\346\226\207/figures/\344\270\200\350\207\264\346\200\247/\345\233\2765_\345\233\233\347\273\204\350\241\250\345\276\201\345\200\231\351\200\211\344\270\255\350\215\257\345\275\222\345\261\236\351\242\204\346\265\213\347\232\204\344\270\245\346\240\274\344\272\244\351\233\206_\346\225\260\346\215\256.xlsx" and "b/\350\256\272\346\226\207/figures/\344\270\200\350\207\264\346\200\247/\345\233\2765_\345\233\233\347\273\204\350\241\250\345\276\201\345\200\231\351\200\211\344\270\255\350\215\257\345\275\222\345\261\236\351\242\204\346\265\213\347\232\204\344\270\245\346\240\274\344\272\244\351\233\206_\346\225\260\346\215\256.xlsx" differ
 
论文/figures/一致性/图6_四组表征两两一致性热图.pdf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:eaa0a212ef824fdae83610897e96064786037e9d5ef86292b71008d090c3b5a9
3
- size 297884
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62c2201220558e69ce9feacf8b23f3fb0d29897aa1ec8a3ce103b024a87cb96d
3
+ size 272593
论文/figures/一致性/图6_四组表征两两一致性热图.png CHANGED

Git LFS Details

  • SHA256: e6290936ca050d5766b31ad31307c25f4618ead3e9e5e0498522a7b2cb722e24
  • Pointer size: 131 Bytes
  • Size of remote file: 525 kB

Git LFS Details

  • SHA256: c715f9d499fd10092e2c9ee6660fffe04a0dd95047367d546981d5e6de45f3f9
  • Pointer size: 131 Bytes
  • Size of remote file: 377 kB
论文/figures/一致性/图6_四组表征两两一致性热图.svg CHANGED
论文/figures/一致性/表12_四组表征两两及总体一致性.xlsx CHANGED
Binary files "a/\350\256\272\346\226\207/figures/\344\270\200\350\207\264\346\200\247/\350\241\25012_\345\233\233\347\273\204\350\241\250\345\276\201\344\270\244\344\270\244\345\217\212\346\200\273\344\275\223\344\270\200\350\207\264\346\200\247.xlsx" and "b/\350\256\272\346\226\207/figures/\344\270\200\350\207\264\346\200\247/\350\241\25012_\345\233\233\347\273\204\350\241\250\345\276\201\344\270\244\344\270\244\345\217\212\346\200\273\344\275\223\344\270\200\350\207\264\346\200\247.xlsx" differ
 
论文/script/图3_关系来源与长尾分布.py CHANGED
@@ -1,5 +1,14 @@
1
  #!/usr/bin/env python3
2
- """分别绘制论文图3A、3B、3C:关系来源支持数与网络长尾分布。"""
 
 
 
 
 
 
 
 
 
3
 
4
  from __future__ import annotations
5
 
@@ -13,6 +22,7 @@ matplotlib.use("Agg")
13
  import matplotlib.pyplot as plt
14
  from matplotlib import font_manager
15
  from openpyxl import load_workbook
 
16
 
17
 
18
  PAPER_DIR = Path(__file__).resolve().parents[1]
@@ -21,11 +31,32 @@ DATA_PATH = PROJECT_DIR / "data" / "中药-化合物数据集" / "整合数据
21
  OUT_DIR = PAPER_DIR / "figures" / "3_1"
22
  SOURCE_COLUMNS = ["BATMAN-TCM", "DCABM-TCM", "ETCM2", "HERB2", "SymMap", "TCMIO", "TM-MC"]
23
 
24
- # 低饱和度柱状图配色(依次对应 1、2、3、4 个及以上数据库)。
25
- BAR_COLORS = ["#6C7A89", "#B1968D", "#9A9E8C", "#D1C8C1"]
26
- HERB_COLOR = BAR_COLORS[0]
27
- COMPOUND_COLOR = BAR_COLORS[2]
28
- TEXT_COLOR = "#222222"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  def first_available_font(candidates: list[str], fallback: str) -> str:
@@ -43,7 +74,10 @@ def configure_style() -> tuple[str, str]:
43
  "STSong",
44
  "Songti SC",
45
  "Noto Serif CJK SC",
 
46
  "Source Han Serif SC",
 
 
47
  ],
48
  "DejaVu Serif",
49
  )
@@ -76,6 +110,7 @@ def configure_style() -> tuple[str, str]:
76
  "axes.labelcolor": TEXT_COLOR,
77
  "xtick.color": TEXT_COLOR,
78
  "ytick.color": TEXT_COLOR,
 
79
  "mathtext.fontset": "stix",
80
  }
81
  )
@@ -142,7 +177,9 @@ def add_panel_label(ax: plt.Axes, label: str, x: float = -0.10, y: float = 1.04)
142
 
143
  def draw_support_distribution(counts: dict[str, int], total: int) -> plt.Figure:
144
  """绘制独立的 A 图(断轴柱状图)。"""
145
- fig = plt.figure(figsize=(8.2, 4.3))
 
 
146
  fig.patch.set_alpha(0)
147
  grid = fig.add_gridspec(2, 1, height_ratios=(1.0, 1.08), hspace=0.07)
148
  ax_top = fig.add_subplot(grid[0])
@@ -177,16 +214,10 @@ def draw_support_distribution(counts: dict[str, int], total: int) -> plt.Figure:
177
  ax_top.spines["bottom"].set_visible(False)
178
  ax_bottom.spines["top"].set_visible(False)
179
  diagonal = 0.010
180
- kwargs = {"color": "#555555", "clip_on": False, "linewidth": 0.85}
181
  ax_top.plot((-diagonal, diagonal), (-diagonal, diagonal), transform=ax_top.transAxes, **kwargs)
182
- ax_top.plot((1 - diagonal, 1 + diagonal), (-diagonal, diagonal), transform=ax_top.transAxes, **kwargs)
183
  ax_bottom.plot((-diagonal, diagonal), (1 - diagonal, 1 + diagonal), transform=ax_bottom.transAxes, **kwargs)
184
- ax_bottom.plot(
185
- (1 - diagonal, 1 + diagonal),
186
- (1 - diagonal, 1 + diagonal),
187
- transform=ax_bottom.transAxes,
188
- **kwargs,
189
- )
190
 
191
  for index, (percentage, count) in enumerate(zip(percentages, count_values)):
192
  target_ax = ax_top if index == 0 else ax_bottom
@@ -202,7 +233,7 @@ def draw_support_distribution(counts: dict[str, int], total: int) -> plt.Figure:
202
  zorder=5,
203
  )
204
 
205
- add_panel_label(ax_top, "A", x=-0.055, y=1.04)
206
  ax_top.text(
207
  0.99,
208
  0.97,
@@ -211,9 +242,9 @@ def draw_support_distribution(counts: dict[str, int], total: int) -> plt.Figure:
211
  ha="right",
212
  va="top",
213
  fontsize=10.2,
214
- color="#4A4A4A",
215
  )
216
- fig.subplots_adjust(left=0.10, right=0.985, bottom=0.15, top=0.94)
217
  return fig
218
 
219
 
@@ -238,8 +269,8 @@ def add_summary_box(ax: plt.Axes, values: list[int], title: str) -> None:
238
  bbox={
239
  "boxstyle": "round,pad=0.30",
240
  "facecolor": "none",
241
- "edgecolor": "#9AA1A8",
242
- "linewidth": 0.45,
243
  },
244
  zorder=5,
245
  )
@@ -254,7 +285,7 @@ def draw_rank_plot(
254
  summary_title: str,
255
  ) -> plt.Figure:
256
  """绘制独立的双对数长尾图。"""
257
- fig, ax = plt.subplots(figsize=(5.0, 4.6))
258
  fig.patch.set_alpha(0)
259
  ranks = list(range(1, len(values) + 1))
260
  ax.fill_between(ranks, values, 1, color=color, alpha=0.14, linewidth=0)
@@ -266,21 +297,53 @@ def draw_rank_plot(
266
  clean_axes(ax)
267
  add_panel_label(ax, panel_label)
268
  add_summary_box(ax, values, summary_title)
269
- fig.subplots_adjust(left=0.16, right=0.97, bottom=0.15, top=0.93)
270
  return fig
271
 
272
 
273
  def save_transparent(fig: plt.Figure, output_path: Path) -> None:
274
  fig.savefig(
275
  output_path,
276
- dpi=450,
277
- bbox_inches="tight",
278
- pad_inches=0.05,
 
279
  transparent=True,
280
  )
281
  plt.close(fig)
282
 
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  def main() -> None:
285
  chinese_font, english_font = configure_style()
286
  OUT_DIR.mkdir(parents=True, exist_ok=True)
@@ -291,6 +354,7 @@ def main() -> None:
291
  OUT_DIR / "图3B_每味中药关联化合物数长尾分布.png",
292
  OUT_DIR / "图3C_每个化合物关联中药数长尾分布.png",
293
  ]
 
294
  save_transparent(draw_support_distribution(counts, total), output_paths[0])
295
  save_transparent(
296
  draw_rank_plot(
@@ -310,15 +374,17 @@ def main() -> None:
310
  "化合物位次",
311
  "关联中药数",
312
  "C",
313
- "每个化合物",
314
  ),
315
  output_paths[2],
316
  )
 
317
 
318
  print(f"字体:中文={chinese_font};英文/数字={english_font}")
319
  print("三张独立透明底图片已保存:")
320
  for path in output_paths:
321
  print(path)
 
322
  print("统计结果:")
323
  for label, count in counts.items():
324
  print(f"{label}: {count:,} ({count / total * 100:.2f}%)")
 
1
  #!/usr/bin/env python3
2
+ """绘制论文图3A、3B、3C,并自动合成上A、下B/C的组图。
3
+
4
+ 三张独立图的画布比例已按最终版式协调:
5
+ - A 图采用宽而稍矮的画布;
6
+ - B、C 图采用完全相同的近方形画布;
7
+ - A 图宽度 = B 图宽度 + 横向间距 + C 图宽度。
8
+
9
+ 因此既可直接使用自动生成的组图,也可在 Word 中手工排版而不会出现
10
+ A 图比下排 B/C 总宽度短的问题。
11
+ """
12
 
13
  from __future__ import annotations
14
 
 
22
  import matplotlib.pyplot as plt
23
  from matplotlib import font_manager
24
  from openpyxl import load_workbook
25
+ from PIL import Image
26
 
27
 
28
  PAPER_DIR = Path(__file__).resolve().parents[1]
 
31
  OUT_DIR = PAPER_DIR / "figures" / "3_1"
32
  SOURCE_COLUMNS = ["BATMAN-TCM", "DCABM-TCM", "ETCM2", "HERB2", "SymMap", "TCMIO", "TM-MC"]
33
 
34
+ # 与图4统一的低饱和度配色。图2的颜色不表示五行属性,
35
+ # 只复用同一色板,以保持整篇论文的视觉一致性。
36
+ PAPER_COLORS = {
37
+ "mu": "#5B8C5A",
38
+ "huo": "#C85A5A",
39
+ "tu": "#E3B750",
40
+ "jin": "#A9A9A9",
41
+ "shui": "#2B4B6F",
42
+ }
43
+ BAR_COLORS = [
44
+ PAPER_COLORS["shui"],
45
+ PAPER_COLORS["huo"],
46
+ PAPER_COLORS["tu"],
47
+ PAPER_COLORS["jin"],
48
+ ]
49
+ HERB_COLOR = PAPER_COLORS["shui"]
50
+ COMPOUND_COLOR = PAPER_COLORS["mu"]
51
+ TEXT_COLOR = "#111111"
52
+ AXIS_COLOR = "#222222"
53
+
54
+ # 最终组图尺寸(英寸)。设计等式:10.60 = 5.05 + 0.50 + 5.05。
55
+ OUTPUT_DPI = 450
56
+ A_FIGSIZE = (10.60, 3.65)
57
+ BC_FIGSIZE = (5.05, 4.55)
58
+ HORIZONTAL_GAP_IN = 0.50
59
+ VERTICAL_GAP_IN = 0.18
60
 
61
 
62
  def first_available_font(candidates: list[str], fallback: str) -> str:
 
74
  "STSong",
75
  "Songti SC",
76
  "Noto Serif CJK SC",
77
+ "Noto Serif CJK JP",
78
  "Source Han Serif SC",
79
+ "Noto Sans CJK SC",
80
+ "Noto Sans CJK JP",
81
  ],
82
  "DejaVu Serif",
83
  )
 
110
  "axes.labelcolor": TEXT_COLOR,
111
  "xtick.color": TEXT_COLOR,
112
  "ytick.color": TEXT_COLOR,
113
+ "axes.edgecolor": AXIS_COLOR,
114
  "mathtext.fontset": "stix",
115
  }
116
  )
 
177
 
178
  def draw_support_distribution(counts: dict[str, int], total: int) -> plt.Figure:
179
  """绘制独立的 A 图(断轴柱状图)。"""
180
+ # A 图宽度与下排 B + 间距 + C 的总宽度严格一致。
181
+ # 同时适当降低高度,避免组图上重下轻。
182
+ fig = plt.figure(figsize=A_FIGSIZE)
183
  fig.patch.set_alpha(0)
184
  grid = fig.add_gridspec(2, 1, height_ratios=(1.0, 1.08), hspace=0.07)
185
  ax_top = fig.add_subplot(grid[0])
 
214
  ax_top.spines["bottom"].set_visible(False)
215
  ax_bottom.spines["top"].set_visible(False)
216
  diagonal = 0.010
217
+ kwargs = {"color": AXIS_COLOR, "clip_on": False, "linewidth": 0.9}
218
  ax_top.plot((-diagonal, diagonal), (-diagonal, diagonal), transform=ax_top.transAxes, **kwargs)
 
219
  ax_bottom.plot((-diagonal, diagonal), (1 - diagonal, 1 + diagonal), transform=ax_bottom.transAxes, **kwargs)
220
+ # 只在左侧纵轴保留断轴符号,避免右侧出现悬空斜线。
 
 
 
 
 
221
 
222
  for index, (percentage, count) in enumerate(zip(percentages, count_values)):
223
  target_ax = ax_top if index == 0 else ax_bottom
 
233
  zorder=5,
234
  )
235
 
236
+ add_panel_label(ax_top, "A", x=-0.045, y=1.04)
237
  ax_top.text(
238
  0.99,
239
  0.97,
 
242
  ha="right",
243
  va="top",
244
  fontsize=10.2,
245
+ color=TEXT_COLOR,
246
  )
247
+ fig.subplots_adjust(left=0.075, right=0.995, bottom=0.17, top=0.93)
248
  return fig
249
 
250
 
 
269
  bbox={
270
  "boxstyle": "round,pad=0.30",
271
  "facecolor": "none",
272
+ "edgecolor": "#5F666C",
273
+ "linewidth": 0.55,
274
  },
275
  zorder=5,
276
  )
 
285
  summary_title: str,
286
  ) -> plt.Figure:
287
  """绘制独立的双对数长尾图。"""
288
+ fig, ax = plt.subplots(figsize=BC_FIGSIZE)
289
  fig.patch.set_alpha(0)
290
  ranks = list(range(1, len(values) + 1))
291
  ax.fill_between(ranks, values, 1, color=color, alpha=0.14, linewidth=0)
 
297
  clean_axes(ax)
298
  add_panel_label(ax, panel_label)
299
  add_summary_box(ax, values, summary_title)
300
+ fig.subplots_adjust(left=0.17, right=0.975, bottom=0.15, top=0.93)
301
  return fig
302
 
303
 
304
  def save_transparent(fig: plt.Figure, output_path: Path) -> None:
305
  fig.savefig(
306
  output_path,
307
+ dpi=OUTPUT_DPI,
308
+ # 保留严格的画布尺寸,使 A 与 B/C 可按设计等式无缩放拼接。
309
+ bbox_inches=None,
310
+ pad_inches=0,
311
  transparent=True,
312
  )
313
  plt.close(fig)
314
 
315
 
316
+ def compose_group_figure(
317
+ panel_a_path: Path,
318
+ panel_b_path: Path,
319
+ panel_c_path: Path,
320
+ output_path: Path,
321
+ ) -> None:
322
+ """将三张透明底面板无拉伸地组合为上A、下B/C的组图。"""
323
+ panel_a = Image.open(panel_a_path).convert("RGBA")
324
+ panel_b = Image.open(panel_b_path).convert("RGBA")
325
+ panel_c = Image.open(panel_c_path).convert("RGBA")
326
+
327
+ horizontal_gap = round(HORIZONTAL_GAP_IN * OUTPUT_DPI)
328
+ vertical_gap = round(VERTICAL_GAP_IN * OUTPUT_DPI)
329
+ bottom_width = panel_b.width + horizontal_gap + panel_c.width
330
+ canvas_width = max(panel_a.width, bottom_width)
331
+ bottom_height = max(panel_b.height, panel_c.height)
332
+ canvas_height = panel_a.height + vertical_gap + bottom_height
333
+
334
+ canvas = Image.new("RGBA", (canvas_width, canvas_height), (255, 255, 255, 0))
335
+ canvas.alpha_composite(panel_a, ((canvas_width - panel_a.width) // 2, 0))
336
+
337
+ bottom_x = (canvas_width - bottom_width) // 2
338
+ bottom_y = panel_a.height + vertical_gap
339
+ canvas.alpha_composite(panel_b, (bottom_x, bottom_y))
340
+ canvas.alpha_composite(
341
+ panel_c,
342
+ (bottom_x + panel_b.width + horizontal_gap, bottom_y),
343
+ )
344
+ canvas.save(output_path, dpi=(OUTPUT_DPI, OUTPUT_DPI))
345
+
346
+
347
  def main() -> None:
348
  chinese_font, english_font = configure_style()
349
  OUT_DIR.mkdir(parents=True, exist_ok=True)
 
354
  OUT_DIR / "图3B_每味中药关联化合物数长尾分布.png",
355
  OUT_DIR / "图3C_每个化合物关联中药数长尾分布.png",
356
  ]
357
+ group_path = OUT_DIR / "图3_数据库来源与长尾分布_组图.png"
358
  save_transparent(draw_support_distribution(counts, total), output_paths[0])
359
  save_transparent(
360
  draw_rank_plot(
 
374
  "化合物位次",
375
  "关联中药数",
376
  "C",
377
+ "有关联记录的化合物",
378
  ),
379
  output_paths[2],
380
  )
381
+ compose_group_figure(*output_paths, group_path)
382
 
383
  print(f"字体:中文={chinese_font};英文/数字={english_font}")
384
  print("三张独立透明底图片已保存:")
385
  for path in output_paths:
386
  print(path)
387
+ print(f"自动组图已保存:{group_path}")
388
  print("统计结果:")
389
  for label, count in counts.items():
390
  print(f"{label}: {count:,} ({count / total * 100:.2f}%)")
论文/script/图表_3_3_二十五味药精版本量化评估.py CHANGED
@@ -28,17 +28,18 @@ WU_CHOICES_PATH = ASSESS_DIR / "吴越版_16组合" / "wu_yue_combination_choice
28
 
29
  CLASS_ORDER = ("木", "火", "土", "金", "水")
30
  CLASS_COLORS = {
31
- "木": "#2F6B4F",
32
- "火": "#B4413E",
33
- "土": "#B48228",
34
- "金": "#777C85",
35
- "水": "#3568A8",
36
  }
37
- COSINE_COLOR = "#007C83"
38
- JACCARD_COLOR = "#D55E00"
39
  AVERAGE_COLOR = "#262626"
40
- GRID_COLOR = "#D8D8D8"
41
- HIGHLIGHT_COLOR = "#E8F3F1"
 
42
 
43
  FIXED_DISPLAY_NAMES = {
44
  "甲版": "1965年范志良抄本",
@@ -56,26 +57,38 @@ REPRESENTATIVE_VERSION_IDS = (
56
 
57
 
58
  def configure_fonts() -> None:
59
- """配置与论文其他章节一致的中文无衬线字体。"""
60
- candidates = [
61
- "Noto Sans CJK SC",
62
- "Source Han Sans SC",
63
- "Microsoft YaHei",
64
- "SimHei",
65
- "WenQuanYi Zen Hei",
66
- "PingFang SC",
67
- "Arial Unicode MS",
68
- ]
69
  available = {font.name for font in font_manager.fontManager.ttflist}
70
- for name in candidates:
71
- if name in available:
72
- plt.rcParams["font.sans-serif"] = [name, "DejaVu Sans"]
73
- break
74
- else:
75
- plt.rcParams["font.sans-serif"] = ["DejaVu Sans"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  plt.rcParams.update(
78
  {
 
 
 
79
  "axes.unicode_minus": False,
80
  "figure.facecolor": "none",
81
  "axes.facecolor": "none",
@@ -84,7 +97,17 @@ def configure_fonts() -> None:
84
  "savefig.transparent": True,
85
  "pdf.fonttype": 42,
86
  "ps.fonttype": 42,
87
- "font.size": 10,
 
 
 
 
 
 
 
 
 
 
88
  }
89
  )
90
 
@@ -203,11 +226,11 @@ def convex_hull_indices(points: np.ndarray) -> np.ndarray | None:
203
 
204
  def style_axis(ax: plt.Axes) -> None:
205
  """应用统一的论文坐标轴样式。"""
206
- ax.grid(axis="x", color=GRID_COLOR, linestyle="--", linewidth=0.6, alpha=0.7)
207
  ax.set_axisbelow(True)
208
  ax.spines["top"].set_visible(False)
209
  ax.spines["right"].set_visible(False)
210
- ax.tick_params(labelsize=9)
211
 
212
 
213
  def add_panel_label(ax: plt.Axes, label: str) -> None:
@@ -218,21 +241,22 @@ def add_panel_label(ax: plt.Axes, label: str) -> None:
218
  transform=ax.transAxes,
219
  ha="right",
220
  va="bottom",
221
- fontsize=13,
222
  fontweight="bold",
223
  )
224
 
225
 
226
  def save_figure(fig: plt.Figure, stem: str) -> None:
227
- """同时导出透明底的300 dpi PNG和矢量PDF。"""
228
  save_options = {
229
  "bbox_inches": "tight",
230
  "facecolor": "none",
231
  "edgecolor": "none",
232
  "transparent": True,
233
  }
234
- fig.savefig(OUT_DIR / f"{stem}.png", dpi=300, **save_options)
235
  fig.savefig(OUT_DIR / f"{stem}.pdf", **save_options)
 
236
  plt.close(fig)
237
 
238
 
@@ -241,18 +265,17 @@ def draw_overall_figure(wide: pd.DataFrame) -> None:
241
  labels = wide["scheme"].tolist()
242
  y_positions = np.arange(len(wide))
243
 
244
- fig, axes = plt.subplots(1, 2, figsize=(15.5, 10.2), sharey=True)
245
- fig.subplots_adjust(left=0.18, right=0.98, top=0.93, bottom=0.15, wspace=0.12)
 
246
 
247
  ax = axes[0]
248
- winner_y = int(wide.index[wide["scheme"] == "W1001"][0])
249
- ax.axhspan(winner_y - 0.45, winner_y + 0.45, color=HIGHLIGHT_COLOR, zorder=0)
250
  for y_pos, row in zip(y_positions, wide.itertuples(index=False)):
251
  ax.plot(
252
  [row.silhouette_mean_cosine, row.silhouette_mean_jaccard],
253
  [y_pos, y_pos],
254
- color="#B9B9B9",
255
- linewidth=1.1,
256
  zorder=1,
257
  )
258
  ax.scatter(
@@ -260,8 +283,8 @@ def draw_overall_figure(wide: pd.DataFrame) -> None:
260
  y_positions,
261
  s=48,
262
  color=COSINE_COLOR,
263
- edgecolor="white",
264
- linewidth=0.7,
265
  label="余弦距离",
266
  zorder=3,
267
  )
@@ -270,29 +293,31 @@ def draw_overall_figure(wide: pd.DataFrame) -> None:
270
  y_positions,
271
  s=48,
272
  color=JACCARD_COLOR,
273
- edgecolor="white",
274
- linewidth=0.7,
275
  label="Jaccard距离",
276
  zorder=3,
277
  )
278
- ax.axvline(0, color="#555555", linewidth=1.0)
279
  ax.set_xlim(-0.10, 0.004)
280
  ax.set_yticks(y_positions, labels)
281
  ax.invert_yaxis()
282
  ax.set_xlabel("平均轮廓系数 S(越大越好)")
283
- ax.set_title("两种距离空间中的平均轮廓系数", fontsize=12, pad=12)
284
- ax.legend(loc="upper center", bbox_to_anchor=(0.5, -0.075), frameon=False, ncol=2)
 
 
 
285
  style_axis(ax)
286
  add_panel_label(ax, "A")
287
 
288
  ax = axes[1]
289
- ax.axhspan(winner_y - 0.45, winner_y + 0.45, color=HIGHLIGHT_COLOR, zorder=0)
290
  for y_pos, row in zip(y_positions, wide.itertuples(index=False)):
291
  ax.plot(
292
  [row.silhouette_rank_cosine, row.silhouette_rank_jaccard],
293
  [y_pos, y_pos],
294
- color="#B9B9B9",
295
- linewidth=1.1,
296
  zorder=1,
297
  )
298
  ax.scatter(
@@ -300,8 +325,8 @@ def draw_overall_figure(wide: pd.DataFrame) -> None:
300
  y_positions,
301
  s=46,
302
  color=COSINE_COLOR,
303
- edgecolor="white",
304
- linewidth=0.7,
305
  label="余弦名次",
306
  zorder=3,
307
  )
@@ -310,8 +335,8 @@ def draw_overall_figure(wide: pd.DataFrame) -> None:
310
  y_positions,
311
  s=46,
312
  color=JACCARD_COLOR,
313
- edgecolor="white",
314
- linewidth=0.7,
315
  label="Jaccard名次",
316
  zorder=3,
317
  )
@@ -331,21 +356,23 @@ def draw_overall_figure(wide: pd.DataFrame) -> None:
331
  xytext=(5, 0),
332
  textcoords="offset points",
333
  va="center",
334
- fontsize=7.5,
335
- color="#333333",
336
  )
337
  ax.set_xlim(0.2, 20.1)
338
  ax.set_xticks([1, 5, 10, 15, 19])
339
  ax.set_xlabel("名次(越小越好)")
340
- ax.set_title("两种距离空间的单项名次与平均名次", fontsize=12, pad=12)
341
- ax.legend(loc="upper center", bbox_to_anchor=(0.5, -0.075), frameon=False, ncol=3, fontsize=8.5)
 
 
 
342
  style_axis(ax)
343
  add_panel_label(ax, "B")
344
 
345
- for tick, scheme in zip(axes[0].get_yticklabels(), labels):
346
- if scheme == "W1001":
347
- tick.set_fontweight("bold")
348
- tick.set_color(COSINE_COLOR)
349
 
350
  save_figure(fig, "图X_十九种方案结构评价与综合排名")
351
 
 
28
 
29
  CLASS_ORDER = ("木", "火", "土", "金", "水")
30
  CLASS_COLORS = {
31
+ "木": "#5B8C5A",
32
+ "火": "#C85A5A",
33
+ "土": "#E3B750",
34
+ "金": "#A9A9A9",
35
+ "水": "#2B4B6F",
36
  }
37
+ COSINE_COLOR = CLASS_COLORS["水"]
38
+ JACCARD_COLOR = CLASS_COLORS["火"]
39
  AVERAGE_COLOR = "#262626"
40
+ GRID_COLOR = "#C8C8C8"
41
+ TEXT_COLOR = "#111111"
42
+ # 图中不对 W1001 另行高亮;其参照方案身份由正文和图注说明。
43
 
44
  FIXED_DISPLAY_NAMES = {
45
  "甲版": "1965年范志良抄本",
 
57
 
58
 
59
  def configure_fonts() -> None:
60
+ """中文优先宋体,英文与数字优先 Times New Roman。"""
 
 
 
 
 
 
 
 
 
61
  available = {font.name for font in font_manager.fontManager.ttflist}
62
+
63
+ chinese_candidates = [
64
+ "SimSun",
65
+ "宋体",
66
+ "STSong",
67
+ "Songti SC",
68
+ "Noto Serif CJK SC",
69
+ "Noto Serif CJK JP",
70
+ "Source Han Serif SC",
71
+ ]
72
+ latin_candidates = [
73
+ "Times New Roman",
74
+ "Times",
75
+ "Liberation Serif",
76
+ "DejaVu Serif",
77
+ ]
78
+ chinese_font = next(
79
+ (name for name in chinese_candidates if name in available),
80
+ "DejaVu Serif",
81
+ )
82
+ latin_font = next(
83
+ (name for name in latin_candidates if name in available),
84
+ "DejaVu Serif",
85
+ )
86
 
87
  plt.rcParams.update(
88
  {
89
+ # Windows 中会命中 Times New Roman + SimSun;其他系统按顺序回退。
90
+ "font.family": [latin_font, chinese_font],
91
+ "font.serif": [latin_font, chinese_font],
92
  "axes.unicode_minus": False,
93
  "figure.facecolor": "none",
94
  "axes.facecolor": "none",
 
97
  "savefig.transparent": True,
98
  "pdf.fonttype": 42,
99
  "ps.fonttype": 42,
100
+ "svg.fonttype": "none",
101
+ "mathtext.fontset": "stix",
102
+ # 图按中文期刊通栏终稿宽度(约17–18 cm)直接设计,
103
+ # 避免先生成超大画布、再在 Word 中缩小导致字号随之缩水。
104
+ "font.size": 8.5,
105
+ "text.color": TEXT_COLOR,
106
+ "axes.labelcolor": TEXT_COLOR,
107
+ "axes.edgecolor": "#222222",
108
+ "xtick.color": TEXT_COLOR,
109
+ "ytick.color": TEXT_COLOR,
110
+ "axes.linewidth": 0.85,
111
  }
112
  )
113
 
 
226
 
227
  def style_axis(ax: plt.Axes) -> None:
228
  """应用统一的论文坐标轴样式。"""
229
+ ax.grid(axis="x", color=GRID_COLOR, linestyle="--", linewidth=0.55, alpha=0.85)
230
  ax.set_axisbelow(True)
231
  ax.spines["top"].set_visible(False)
232
  ax.spines["right"].set_visible(False)
233
+ ax.tick_params(labelsize=7.8, width=0.8, colors=TEXT_COLOR)
234
 
235
 
236
  def add_panel_label(ax: plt.Axes, label: str) -> None:
 
241
  transform=ax.transAxes,
242
  ha="right",
243
  va="bottom",
244
+ fontsize=10.5,
245
  fontweight="bold",
246
  )
247
 
248
 
249
  def save_figure(fig: plt.Figure, stem: str) -> None:
250
+ """导出透明底的600 dpi PNG、矢量PDF和SVG。"""
251
  save_options = {
252
  "bbox_inches": "tight",
253
  "facecolor": "none",
254
  "edgecolor": "none",
255
  "transparent": True,
256
  }
257
+ fig.savefig(OUT_DIR / f"{stem}.png", dpi=600, **save_options)
258
  fig.savefig(OUT_DIR / f"{stem}.pdf", **save_options)
259
+ fig.savefig(OUT_DIR / f"{stem}.svg", **save_options)
260
  plt.close(fig)
261
 
262
 
 
265
  labels = wide["scheme"].tolist()
266
  y_positions = np.arange(len(wide))
267
 
268
+ # 7.1 in × 5.45 in 约对应中文期刊17–18 cm通栏图。
269
+ fig, axes = plt.subplots(1, 2, figsize=(7.1, 5.45), sharey=True)
270
+ fig.subplots_adjust(left=0.205, right=0.99, top=0.90, bottom=0.15, wspace=0.14)
271
 
272
  ax = axes[0]
 
 
273
  for y_pos, row in zip(y_positions, wide.itertuples(index=False)):
274
  ax.plot(
275
  [row.silhouette_mean_cosine, row.silhouette_mean_jaccard],
276
  [y_pos, y_pos],
277
+ color="#8F969C",
278
+ linewidth=0.9,
279
  zorder=1,
280
  )
281
  ax.scatter(
 
283
  y_positions,
284
  s=48,
285
  color=COSINE_COLOR,
286
+ edgecolor="#FFFFFF",
287
+ linewidth=0.55,
288
  label="余弦距离",
289
  zorder=3,
290
  )
 
293
  y_positions,
294
  s=48,
295
  color=JACCARD_COLOR,
296
+ edgecolor="#FFFFFF",
297
+ linewidth=0.55,
298
  label="Jaccard距离",
299
  zorder=3,
300
  )
301
+ ax.axvline(0, color="#333333", linewidth=0.9)
302
  ax.set_xlim(-0.10, 0.004)
303
  ax.set_yticks(y_positions, labels)
304
  ax.invert_yaxis()
305
  ax.set_xlabel("平均轮廓系数 S(越大越好)")
306
+ ax.set_title("平均轮廓系数", fontsize=9.2, pad=8)
307
+ ax.legend(
308
+ loc="upper center", bbox_to_anchor=(0.5, -0.09), frameon=False,
309
+ ncol=2, fontsize=7.6, handletextpad=0.4, columnspacing=0.9,
310
+ )
311
  style_axis(ax)
312
  add_panel_label(ax, "A")
313
 
314
  ax = axes[1]
 
315
  for y_pos, row in zip(y_positions, wide.itertuples(index=False)):
316
  ax.plot(
317
  [row.silhouette_rank_cosine, row.silhouette_rank_jaccard],
318
  [y_pos, y_pos],
319
+ color="#8F969C",
320
+ linewidth=0.9,
321
  zorder=1,
322
  )
323
  ax.scatter(
 
325
  y_positions,
326
  s=46,
327
  color=COSINE_COLOR,
328
+ edgecolor="#FFFFFF",
329
+ linewidth=0.55,
330
  label="余弦名次",
331
  zorder=3,
332
  )
 
335
  y_positions,
336
  s=46,
337
  color=JACCARD_COLOR,
338
+ edgecolor="#FFFFFF",
339
+ linewidth=0.55,
340
  label="Jaccard名次",
341
  zorder=3,
342
  )
 
356
  xytext=(5, 0),
357
  textcoords="offset points",
358
  va="center",
359
+ fontsize=7.2,
360
+ color=TEXT_COLOR,
361
  )
362
  ax.set_xlim(0.2, 20.1)
363
  ax.set_xticks([1, 5, 10, 15, 19])
364
  ax.set_xlabel("名次(越小越好)")
365
+ ax.set_title("单项名次与平均名次", fontsize=9.2, pad=8)
366
+ ax.legend(
367
+ loc="upper center", bbox_to_anchor=(0.5, -0.09), frameon=False,
368
+ ncol=3, fontsize=7.2, handletextpad=0.35, columnspacing=0.65,
369
+ )
370
  style_axis(ax)
371
  add_panel_label(ax, "B")
372
 
373
+ for tick in axes[0].get_yticklabels():
374
+ tick.set_fontsize(7.5)
375
+ tick.set_color(TEXT_COLOR)
 
376
 
377
  save_figure(fig, "图X_十九种方案结构评价与综合排名")
378
 
论文/script/拼接图4_无重叠.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """把图4的 A、B、C 自动拼为中文期刊通栏版:A、B、C 等宽竖排。
3
+
4
+ 原来 A+B 同排时,两个面板在 Word 中各只占半栏,热图标签和数值会
5
+ 缩到4–5 pt左右。新版将三个面板都按7 in通栏宽度设计并竖向组合,
6
+ 不再对文字进行二次缩小。
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from pathlib import Path
12
+
13
+ from PIL import Image
14
+
15
+
16
+ PAPER_DIR = Path(__file__).resolve().parents[1]
17
+ FIGURE_DIR = PAPER_DIR / "figures" / "一致性"
18
+
19
+ A_PATH = FIGURE_DIR / "图4_四组表征预测类别分布.png"
20
+ B_PATH = FIGURE_DIR / "图6_四组表征两两一致性热图.png"
21
+ C_PATH = FIGURE_DIR / "图5_四组表征候选中药归属预测的严格交集.png"
22
+ OUT_PATH = FIGURE_DIR / "图4_四组表征一致性分析_拼接版.png"
23
+
24
+ OUTPUT_DPI = 600
25
+ OUTER_MARGIN = 54
26
+ VERTICAL_GAP = 72
27
+
28
+
29
+ def trim_transparent(image: Image.Image, padding: int = 24) -> Image.Image:
30
+ """按透明通道裁掉导出时的多余画布,同时保留安全边距。"""
31
+ rgba = image.convert("RGBA")
32
+ alpha = rgba.getchannel("A")
33
+ bbox = alpha.getbbox()
34
+ if bbox is None:
35
+ return rgba
36
+ left, top, right, bottom = bbox
37
+ left = max(0, left - padding)
38
+ top = max(0, top - padding)
39
+ right = min(rgba.width, right + padding)
40
+ bottom = min(rgba.height, bottom + padding)
41
+ return rgba.crop((left, top, right, bottom))
42
+
43
+
44
+ def normalize_width(image: Image.Image, width: int) -> Image.Image:
45
+ """仅在旧图尺寸不一致时按比例对齐宽度;新脚本生成图通常无需缩放。"""
46
+ if image.width == width:
47
+ return image
48
+ height = round(image.height * width / image.width)
49
+ return image.resize((width, height), Image.Resampling.LANCZOS)
50
+
51
+
52
+ def paste_rgba(canvas: Image.Image, image: Image.Image, xy: tuple[int, int]) -> None:
53
+ canvas.paste(image, xy, image)
54
+
55
+
56
+ def main() -> None:
57
+ for path in (A_PATH, B_PATH, C_PATH):
58
+ if not path.exists():
59
+ raise FileNotFoundError(f"缺少源图,请先运行一致性分析脚本:{path}")
60
+
61
+ panels = [trim_transparent(Image.open(path), padding=18) for path in (A_PATH, B_PATH, C_PATH)]
62
+ # 三张源图均按7 in设计;裁剪后取最大内容宽度对齐。
63
+ content_width = max(panel.width for panel in panels)
64
+ panel_a, panel_b, panel_c = [normalize_width(panel, content_width) for panel in panels]
65
+
66
+ canvas_width = content_width + 2 * OUTER_MARGIN
67
+ canvas_height = (
68
+ 2 * OUTER_MARGIN
69
+ + panel_a.height
70
+ + panel_b.height
71
+ + panel_c.height
72
+ + 2 * VERTICAL_GAP
73
+ )
74
+ # 保留透明通道;不要使用 RGB 白色画布,否则会把源图透明底吃掉。
75
+ canvas = Image.new("RGBA", (canvas_width, canvas_height), (255, 255, 255, 0))
76
+
77
+ current_y = OUTER_MARGIN
78
+ for index, panel in enumerate((panel_a, panel_b, panel_c)):
79
+ x = OUTER_MARGIN + (content_width - panel.width) // 2
80
+ paste_rgba(canvas, panel, (x, current_y))
81
+ current_y += panel.height
82
+ if index < 2:
83
+ current_y += VERTICAL_GAP
84
+
85
+ OUT_PATH.parent.mkdir(parents=True, exist_ok=True)
86
+ canvas.save(OUT_PATH, dpi=(OUTPUT_DPI, OUTPUT_DPI), optimize=True)
87
+ print(f"已保存:{OUT_PATH}")
88
+
89
+
90
+ if __name__ == "__main__":
91
+ main()
论文/script/生成_3_5_2_一致性图表.py CHANGED
@@ -20,7 +20,7 @@ import matplotlib as mpl
20
  import matplotlib.pyplot as plt
21
  import numpy as np
22
  from matplotlib.colors import Normalize
23
- from matplotlib.font_manager import FontProperties, findfont
24
  from matplotlib.patches import Rectangle
25
  from openpyxl import Workbook
26
  from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
@@ -88,15 +88,31 @@ PATTERN_CONSENSUS = {
88
 
89
 
90
  def configure_matplotlib() -> None:
91
- # 当前计算环境没有微软宋体和 Times New Roman 字体文件。绘图时分别使用
92
- # 字形风格相近的 Noto Serif CJK SC 与 Liberation Serif。后者与 Times New
93
- # Roman 度量兼容,前者为简体中文宋体类(衬线)字体。
94
- chinese_fallback = "Noto Serif CJK SC"
95
- latin_fallback = "Liberation Serif"
96
- if not Path(findfont(FontProperties(family=chinese_fallback))).exists():
97
- raise RuntimeError(f"缺少中文宋体类字体:{chinese_fallback}")
98
- if not Path(findfont(FontProperties(family=latin_fallback))).exists():
99
- raise RuntimeError(f"缺少 Times New Roman 兼容字体:{latin_fallback}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  mpl.rcParams.update(
101
  {
102
  "font.family": [
@@ -118,11 +134,13 @@ def configure_matplotlib() -> None:
118
  "axes.facecolor": "none",
119
  "savefig.facecolor": "none",
120
  "savefig.transparent": True,
121
- "axes.edgecolor": "#333333",
122
- "axes.linewidth": 0.8,
123
- "xtick.color": "#333333",
124
- "ytick.color": "#333333",
125
- "text.color": "#222222",
 
 
126
  }
127
  )
128
 
@@ -236,7 +254,10 @@ def save_figure(fig: plt.Figure, stem: str) -> None:
236
  output_path = OUTPUT_DIR / f"{stem}.{suffix}"
237
  fig.savefig(
238
  output_path,
239
- bbox_inches="tight",
 
 
 
240
  facecolor="none",
241
  edgecolor="none",
242
  transparent=True,
@@ -253,7 +274,7 @@ def save_figure(fig: plt.Figure, stem: str) -> None:
253
 
254
 
255
  def plot_distribution(dist: dict[str, Counter[str]]) -> None:
256
- fig, ax = plt.subplots(figsize=(9.0, 5.8))
257
  x = np.arange(len(METHODS))
258
  bottom = np.zeros(len(METHODS))
259
  width = 0.68
@@ -279,27 +300,29 @@ def plot_distribution(dist: dict[str, Counter[str]]) -> None:
279
  f"{pct:.1f}%",
280
  ha="center",
281
  va="center",
282
- fontsize=9.0,
283
  color=text_color,
284
  fontweight="normal",
285
  )
286
  bottom += percentages
287
 
288
- ax.set_xticks(x, [METHOD_NAMES[m] for m in METHODS], fontsize=10.5)
289
- ax.set_ylabel("候选中药比例(%)", fontsize=11)
290
  ax.set_ylim(0, 100)
291
  ax.set_yticks(np.arange(0, 101, 20))
292
  ax.spines[["top", "right"]].set_visible(False)
293
  ax.legend(
294
  ncol=5,
295
  loc="upper center",
296
- bbox_to_anchor=(0.5, 1.11),
 
297
  frameon=False,
298
- fontsize=9.5,
299
  handlelength=1.2,
300
  columnspacing=1.25,
301
  )
302
- fig.subplots_adjust(top=0.85, bottom=0.13, left=0.11, right=0.98)
 
303
  save_figure(fig, "图4_四组表征预测类别分布")
304
 
305
 
@@ -307,37 +330,36 @@ def plot_upset(intersections: Counter[tuple[str, ...]]) -> None:
307
  combos = sorted(intersections, key=lambda c: (-len(c), -intersections[c], tuple(METHODS.index(m) for m in c)))
308
  sizes = [intersections[combo] for combo in combos]
309
  degrees = [len(combo) for combo in combos]
310
- degree_colors = {4: "#A63D40", 3: "#E79B38", 2: "#4C78A8", 1: "#AEB5BD"}
311
-
312
- fig = plt.figure(figsize=(14.2, 8.0))
 
 
 
 
 
 
313
  grid = fig.add_gridspec(
314
  2,
315
- 2,
316
- width_ratios=[2.25, 9.0],
317
- height_ratios=[4.5, 2.4],
318
- wspace=0.05,
319
- hspace=0.08,
320
  )
321
- ax_blank = fig.add_subplot(grid[0, 0])
322
- ax_bar = fig.add_subplot(grid[0, 1])
323
- ax_set = fig.add_subplot(grid[1, 0])
324
- ax_matrix = fig.add_subplot(grid[1, 1], sharex=ax_bar)
325
- ax_blank.axis("off")
326
 
327
  x = np.arange(len(combos))
328
  ax_bar.bar(x, sizes, color=[degree_colors[d] for d in degrees], width=0.72)
329
  for i, size in enumerate(sizes):
330
- ax_bar.text(i, size + 5, str(size), ha="center", va="bottom", fontsize=9.2, rotation=90)
331
- ax_bar.set_ylabel("严格交集大小(中药—标签配对数)", fontsize=11)
332
  ax_bar.set_ylim(0, max(sizes) * 1.18)
333
  ax_bar.set_xlim(-0.6, len(combos) - 0.4)
334
  ax_bar.spines[["top", "right"]].set_visible(False)
335
  ax_bar.tick_params(axis="x", bottom=False, labelbottom=False)
336
 
337
  row_y = np.arange(len(METHODS))[::-1]
338
- for y_index, y in enumerate(row_y):
339
- if y_index % 2 == 0:
340
- ax_matrix.axhspan(y - 0.5, y + 0.5, color="#F1F3F5", zorder=0)
341
  for i, combo in enumerate(combos):
342
  active_y = [row_y[METHODS.index(method)] for method in combo]
343
  ax_matrix.scatter([i] * len(METHODS), row_y, s=48, color="#D4D8DC", zorder=2)
@@ -345,22 +367,17 @@ def plot_upset(intersections: Counter[tuple[str, ...]]) -> None:
345
  ax_matrix.plot([i, i], [min(active_y), max(active_y)], color="#252A2E", linewidth=1.5, zorder=3)
346
  ax_matrix.scatter([i] * len(active_y), active_y, s=68, color="#252A2E", zorder=4)
347
  ax_matrix.set_ylim(-0.6, len(METHODS) - 0.4)
348
- ax_matrix.set_yticks(row_y, [METHOD_NAMES[m] for m in METHODS], fontsize=10.5)
349
- ax_matrix.set_xlabel("严格表征组合(按支持表征数及交集大小排序)", fontsize=11)
 
350
  ax_matrix.spines[["top", "right", "left"]].set_visible(False)
351
  ax_matrix.tick_params(axis="x", bottom=False, labelbottom=False)
352
  ax_matrix.tick_params(axis="y", length=0, pad=8)
353
 
354
- ax_set.barh(row_y, [570] * len(METHODS), color="#7E8790", height=0.55)
355
- for y in row_y:
356
- ax_set.text(285, y, "570", ha="center", va="center", color="white", fontweight="bold", fontsize=10.5)
357
- ax_set.set_xlim(610, 0)
358
- ax_set.set_yticks([])
359
- ax_set.set_xlabel("集合大小", fontsize=10.5)
360
- ax_set.spines[["top", "right", "left"]].set_visible(False)
361
- ax_set.tick_params(axis="y", length=0)
362
-
363
- fig.subplots_adjust(left=0.07, right=0.99, top=0.98, bottom=0.08)
364
  save_figure(fig, "图5_四组表征候选中药归属预测的严格交集")
365
 
366
 
@@ -373,7 +390,7 @@ def plot_pairwise_heatmaps(pairwise: dict[tuple[str, str], tuple[float, float]])
373
  agreement[i, j] = agreement[j, i] = rate * 100
374
  kappa[i, j] = kappa[j, i] = kap
375
 
376
- fig, axes = plt.subplots(1, 2, figsize=(11.6, 5.2))
377
  specs = [
378
  (agreement, "两两原始一致率", "原始一致率(%)", mpl.colormaps["Blues"], 15, 40, lambda v: f"{v:.1f}%"),
379
  (kappa, "两两 Cohen’s κ", "Cohen’s κ", mpl.colormaps["YlOrBr"], 0, 0.18, lambda v: f"{v:.3f}"),
@@ -384,17 +401,17 @@ def plot_pairwise_heatmaps(pairwise: dict[tuple[str, str], tuple[float, float]])
384
  image = ax.imshow(shown, cmap=cmap, norm=Normalize(vmin=vmin, vmax=vmax), aspect="equal")
385
  for i in range(n):
386
  ax.add_patch(Rectangle((i - 0.5, i - 0.5), 1, 1, facecolor="#ECEFF1", edgecolor="white", linewidth=2))
387
- ax.text(i, i, "—", ha="center", va="center", color="#777777", fontsize=11)
388
  for j in range(n):
389
  if i == j:
390
  continue
391
  value = matrix[i, j]
392
  midpoint = (vmin + vmax) / 2
393
- color = "white" if value > midpoint else "#222222"
394
- ax.text(j, i, formatter(value), ha="center", va="center", color=color, fontsize=9.4)
395
- ax.set_xticks(np.arange(n), labels, rotation=28, ha="right", fontsize=9.3)
396
- ax.set_yticks(np.arange(n), labels, fontsize=9.3)
397
- ax.set_title(title, loc="left", fontsize=11.5, fontweight="bold", pad=10)
398
  ax.set_xticks(np.arange(-0.5, n, 1), minor=True)
399
  ax.set_yticks(np.arange(-0.5, n, 1), minor=True)
400
  ax.grid(which="minor", color="white", linewidth=2)
@@ -402,9 +419,10 @@ def plot_pairwise_heatmaps(pairwise: dict[tuple[str, str], tuple[float, float]])
402
  for spine in ax.spines.values():
403
  spine.set_visible(False)
404
  cbar = fig.colorbar(image, ax=ax, fraction=0.046, pad=0.04)
405
- cbar.set_label(colorbar_label, fontsize=9.2)
406
- cbar.ax.tick_params(labelsize=8.5)
407
- fig.subplots_adjust(left=0.09, right=0.96, top=0.90, bottom=0.14, wspace=0.30)
 
408
  save_figure(fig, "图6_四组表征两两一致性热图")
409
 
410
 
 
20
  import matplotlib.pyplot as plt
21
  import numpy as np
22
  from matplotlib.colors import Normalize
23
+ from matplotlib import font_manager
24
  from matplotlib.patches import Rectangle
25
  from openpyxl import Workbook
26
  from openpyxl.styles import Alignment, Border, Font, PatternFill, Side
 
88
 
89
 
90
  def configure_matplotlib() -> None:
91
+ # 优先使用论文目标字体;在 Linux 环境中则使用可用的 CJK
92
+ # 衬线字体补字。不再硬编码单一字体名,避免中文变成方框。
93
+ available = {font.name for font in font_manager.fontManager.ttflist}
94
+
95
+ def first_available(candidates: list[str], fallback: str) -> str:
96
+ return next((name for name in candidates if name in available), fallback)
97
+
98
+ chinese_fallback = first_available(
99
+ [
100
+ "SimSun",
101
+ "宋体",
102
+ "STSong",
103
+ "Songti SC",
104
+ "Noto Serif CJK SC",
105
+ "Noto Serif CJK JP",
106
+ "Source Han Serif SC",
107
+ "Noto Sans CJK SC",
108
+ "Noto Sans CJK JP",
109
+ ],
110
+ "DejaVu Sans",
111
+ )
112
+ latin_fallback = first_available(
113
+ ["Times New Roman", "Times", "Liberation Serif"],
114
+ "DejaVu Serif",
115
+ )
116
  mpl.rcParams.update(
117
  {
118
  "font.family": [
 
134
  "axes.facecolor": "none",
135
  "savefig.facecolor": "none",
136
  "savefig.transparent": True,
137
+ "font.size": 9.0,
138
+ "axes.edgecolor": "#222222",
139
+ "axes.linewidth": 0.9,
140
+ "xtick.color": "#111111",
141
+ "ytick.color": "#111111",
142
+ "axes.labelcolor": "#111111",
143
+ "text.color": "#111111",
144
  }
145
  )
146
 
 
254
  output_path = OUTPUT_DIR / f"{stem}.{suffix}"
255
  fig.savefig(
256
  output_path,
257
+ # 三个面板都按7 in通栏宽度直接设计;保留精确画布尺寸,
258
+ # 后续竖向拼图时不再缩放文字。
259
+ bbox_inches=None,
260
+ pad_inches=0,
261
  facecolor="none",
262
  edgecolor="none",
263
  transparent=True,
 
274
 
275
 
276
  def plot_distribution(dist: dict[str, Counter[str]]) -> None:
277
+ fig, ax = plt.subplots(figsize=(7.0, 2.65))
278
  x = np.arange(len(METHODS))
279
  bottom = np.zeros(len(METHODS))
280
  width = 0.68
 
300
  f"{pct:.1f}%",
301
  ha="center",
302
  va="center",
303
+ fontsize=8.3,
304
  color=text_color,
305
  fontweight="normal",
306
  )
307
  bottom += percentages
308
 
309
+ ax.set_xticks(x, [METHOD_NAMES[m] for m in METHODS], fontsize=8.7)
310
+ ax.set_ylabel("候选中药比例(%)", fontsize=9.2)
311
  ax.set_ylim(0, 100)
312
  ax.set_yticks(np.arange(0, 101, 20))
313
  ax.spines[["top", "right"]].set_visible(False)
314
  ax.legend(
315
  ncol=5,
316
  loc="upper center",
317
+ # 图例独占柱图上方的留白区,避免与100%柱顶重叠。
318
+ bbox_to_anchor=(0.5, 1.25),
319
  frameon=False,
320
+ fontsize=8.0,
321
  handlelength=1.2,
322
  columnspacing=1.25,
323
  )
324
+ fig.text(0.012, 0.965, "A", ha="left", va="top", fontsize=11, fontweight="bold")
325
+ fig.subplots_adjust(top=0.72, bottom=0.20, left=0.105, right=0.985)
326
  save_figure(fig, "图4_四组表征预测类别分布")
327
 
328
 
 
330
  combos = sorted(intersections, key=lambda c: (-len(c), -intersections[c], tuple(METHODS.index(m) for m in c)))
331
  sizes = [intersections[combo] for combo in combos]
332
  degrees = [len(combo) for combo in combos]
333
+ # 交集柱图也只使用图4的五色体系和中性灰。
334
+ degree_colors = {
335
+ 4: LABEL_COLORS["Huo(Salty)"],
336
+ 3: LABEL_COLORS["Tu(Sweet)"],
337
+ 2: LABEL_COLORS["Shui(Bitter)"],
338
+ 1: LABEL_COLORS["Jin(Sour)"],
339
+ }
340
+
341
+ fig = plt.figure(figsize=(7.0, 3.45))
342
  grid = fig.add_gridspec(
343
  2,
344
+ 1,
345
+ height_ratios=[3.7, 1.65],
346
+ hspace=0.06,
 
 
347
  )
348
+ ax_bar = fig.add_subplot(grid[0, 0])
349
+ ax_matrix = fig.add_subplot(grid[1, 0], sharex=ax_bar)
 
 
 
350
 
351
  x = np.arange(len(combos))
352
  ax_bar.bar(x, sizes, color=[degree_colors[d] for d in degrees], width=0.72)
353
  for i, size in enumerate(sizes):
354
+ ax_bar.text(i, size + 5, str(size), ha="center", va="bottom", fontsize=7.8, rotation=90)
355
+ ax_bar.set_ylabel("严格交集大小(中药—标签配对数)", fontsize=8.8)
356
  ax_bar.set_ylim(0, max(sizes) * 1.18)
357
  ax_bar.set_xlim(-0.6, len(combos) - 0.4)
358
  ax_bar.spines[["top", "right"]].set_visible(False)
359
  ax_bar.tick_params(axis="x", bottom=False, labelbottom=False)
360
 
361
  row_y = np.arange(len(METHODS))[::-1]
362
+ # 点阵区保持完全透明,不再绘制交替的浅灰/白色行底纹。
 
 
363
  for i, combo in enumerate(combos):
364
  active_y = [row_y[METHODS.index(method)] for method in combo]
365
  ax_matrix.scatter([i] * len(METHODS), row_y, s=48, color="#D4D8DC", zorder=2)
 
367
  ax_matrix.plot([i, i], [min(active_y), max(active_y)], color="#252A2E", linewidth=1.5, zorder=3)
368
  ax_matrix.scatter([i] * len(active_y), active_y, s=68, color="#252A2E", zorder=4)
369
  ax_matrix.set_ylim(-0.6, len(METHODS) - 0.4)
370
+ ax_matrix.set_yticks(row_y, [METHOD_NAMES[m] for m in METHODS], fontsize=8.7)
371
+ # 组合的排序规则在图注中说明,不再在图底部重复显示长横轴标题。
372
+ ax_matrix.set_xlabel("")
373
  ax_matrix.spines[["top", "right", "left"]].set_visible(False)
374
  ax_matrix.tick_params(axis="x", bottom=False, labelbottom=False)
375
  ax_matrix.tick_params(axis="y", length=0, pad=8)
376
 
377
+ # 不再绘制左侧的集合大小条形和重复的“570”。
378
+ # 矩阵左侧仅保留四种表征名称,整幅 C 图可直接紧凑裁切。
379
+ fig.text(0.012, 0.975, "C", ha="left", va="top", fontsize=11, fontweight="bold")
380
+ fig.subplots_adjust(left=0.16, right=0.995, top=0.95, bottom=0.075)
 
 
 
 
 
 
381
  save_figure(fig, "图5_四组表征候选中药归属预测的严格交集")
382
 
383
 
 
390
  agreement[i, j] = agreement[j, i] = rate * 100
391
  kappa[i, j] = kappa[j, i] = kap
392
 
393
+ fig, axes = plt.subplots(1, 2, figsize=(7.0, 2.95))
394
  specs = [
395
  (agreement, "两两原始一致率", "原始一致率(%)", mpl.colormaps["Blues"], 15, 40, lambda v: f"{v:.1f}%"),
396
  (kappa, "两两 Cohen’s κ", "Cohen’s κ", mpl.colormaps["YlOrBr"], 0, 0.18, lambda v: f"{v:.3f}"),
 
401
  image = ax.imshow(shown, cmap=cmap, norm=Normalize(vmin=vmin, vmax=vmax), aspect="equal")
402
  for i in range(n):
403
  ax.add_patch(Rectangle((i - 0.5, i - 0.5), 1, 1, facecolor="#ECEFF1", edgecolor="white", linewidth=2))
404
+ ax.text(i, i, "—", ha="center", va="center", color="#4F4F4F", fontsize=9.0)
405
  for j in range(n):
406
  if i == j:
407
  continue
408
  value = matrix[i, j]
409
  midpoint = (vmin + vmax) / 2
410
+ color = "white" if value > midpoint else "#111111"
411
+ ax.text(j, i, formatter(value), ha="center", va="center", color=color, fontsize=8.0)
412
+ ax.set_xticks(np.arange(n), labels, rotation=24, ha="right", fontsize=7.5)
413
+ ax.set_yticks(np.arange(n), labels, fontsize=7.5)
414
+ ax.set_title(title, loc="left", fontsize=9.5, fontweight="bold", pad=7)
415
  ax.set_xticks(np.arange(-0.5, n, 1), minor=True)
416
  ax.set_yticks(np.arange(-0.5, n, 1), minor=True)
417
  ax.grid(which="minor", color="white", linewidth=2)
 
419
  for spine in ax.spines.values():
420
  spine.set_visible(False)
421
  cbar = fig.colorbar(image, ax=ax, fraction=0.046, pad=0.04)
422
+ cbar.set_label(colorbar_label, fontsize=7.5)
423
+ cbar.ax.tick_params(labelsize=7.0)
424
+ fig.text(0.012, 0.965, "B", ha="left", va="top", fontsize=11, fontweight="bold")
425
+ fig.subplots_adjust(left=0.105, right=0.975, top=0.86, bottom=0.22, wspace=0.30)
426
  save_figure(fig, "图6_四组表征两两一致性热图")
427
 
428