"""4개교 전 마크 모델 형상 일람(2D 투영) — 도면 형상 상세와 마크별 눈으로 대조하기 위한 이미지. 입력: jobs/c1_work/c1_shape_audit2.json (c1_shape_audit2.py). 출력: 검토파일/수정후_캡처/형상일람_<교량>_<부재>.png""" import json from pathlib import Path import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from matplotlib import font_manager font_manager.fontManager.addfont(r"C:\Windows\Fonts\malgun.ttf") plt.rcParams["font.family"] = "Malgun Gothic" D = json.load(open(r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_shape_audit2.json", encoding="utf-8-sig")) OUT = Path(r"D:\★Pier 자료\프로그램\Pier_T\검토파일\수정후_캡처") PART = {"P1-FT": "기초", "P1-CP": "코핑", "P1-CL": "기둥", "P1-PL01": "말뚝", "P1-PL02": "말뚝"} made = [] for br, items in D.items(): for part in ("기초", "코핑", "기둥", "말뚝"): its = [x for x in items if PART.get(x["host"]) == part] if not its: continue its.sort(key=lambda x: (len(x["mark"]), x["mark"])) cols = 4 rows = (len(its) + cols - 1) // cols fig, axs = plt.subplots(rows, cols, figsize=(cols * 4.2, rows * 3.3)) axs = np.atleast_2d(axs) for ax in axs.ravel(): ax.axis("off") for ax, x in zip(axs.ravel(), its): P = np.array(x["pts"]) C = P - P.mean(0) u, s, vt = np.linalg.svd(C, full_matrices=False) Q = C @ vt[:2].T ax.plot(Q[:, 0], Q[:, 1], "-", color="#1f77b4", lw=2) ax.plot(*Q[0], "o", color="green", ms=5); ax.plot(*Q[-1], "s", color="red", ms=5) w, h = np.ptp(Q[:, 0]), np.ptp(Q[:, 1]) if h < 0.2 * w or w < 0.2 * h: ax.set_aspect("auto"); ax.margins(0.08) note = "※ 가로세로 비율 왜곡(형상 확인용)" else: ax.set_aspect("equal"); note = "" ax.axis("on"); ax.set_xticks([]); ax.set_yticks([]) pc = " · %d조각" % x["pieces"] if x["pieces"] else "" ax.set_title("%s 형식 %s %s N=%d%s" % (x["mark"], x["shape"], x["dia"], x["n_obj"], pc), fontsize=11, fontweight="bold") ax.set_xlabel(note + "\nL(표)=%s 모델 %s 직선 %s" % (x["design_len"].split(".")[0] if x["design_len"] else "-", x["len"], ",".join(str(v) for v in x["lin_lens"][:5])), fontsize=8) fig.suptitle("%s교 %s 철근 — 모델 형상 일람 (초록 ●=시작 / 빨강 ■=끝, 2D 투영, 마크별 대표 1본)" % (br, part), fontsize=15, fontweight="bold") fig.tight_layout(rect=(0, 0, 1, 0.96)) p = OUT / ("형상일람_%s_%s.png" % (br, part)) fig.savefig(p, dpi=75); plt.close(fig) made.append(p.name) print(made)