render_project_self_loops.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """单独渲染项目节点的两条自回边,便于核对 包含/续签自 关系。"""
  2. from __future__ import annotations
  3. import matplotlib
  4. matplotlib.use("Agg")
  5. import matplotlib.pyplot as plt
  6. OUT = r"E:\CODE\knowledge_agent\meta_graph_project_self_loops.png"
  7. def main() -> None:
  8. fig, ax = plt.subplots(figsize=(7, 5))
  9. ax.scatter([0], [0], s=3600, c="#4C9F70", edgecolors="white", linewidths=2)
  10. ax.text(0, 0, "项目", ha="center", va="center", color="white", fontsize=14,
  11. family="Microsoft YaHei")
  12. items = [
  13. ("包含\n(层级序号 父→子)", "#2E75B6", 0.55, 0.38),
  14. ("续签自\n(续签前项目编号)", "#C55A11", -0.55, -0.38),
  15. ]
  16. for label, color, rad, dy in items:
  17. ax.annotate(
  18. "",
  19. xy=(0.16, dy),
  20. xytext=(-0.16, dy),
  21. arrowprops=dict(
  22. arrowstyle="-|>",
  23. color=color,
  24. lw=3,
  25. connectionstyle=f"arc3,rad={rad}",
  26. mutation_scale=22,
  27. ),
  28. )
  29. ax.text(0, dy + (0.58 if dy > 0 else -0.58), label, ha="center", va="center",
  30. fontsize=10, family="Microsoft YaHei", color=color)
  31. ax.set_xlim(-1.6, 1.6)
  32. ax.set_ylim(-1.6, 1.6)
  33. ax.set_aspect("equal")
  34. ax.axis("off")
  35. ax.set_title("项目自回边:包含 / 续签自", family="Microsoft YaHei", fontsize=15)
  36. fig.tight_layout()
  37. fig.savefig(OUT, dpi=150, bbox_inches="tight")
  38. print(OUT)
  39. if __name__ == "__main__":
  40. main()