169 lines
4.2 KiB
Python
169 lines
4.2 KiB
Python
|
|
"""对比度测试结果绘制。
|
|||
|
|
|
|||
|
|
Step 2 重构:从 pqAutomationApp.PQAutomationApp.plot_contrast 原样搬迁。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from matplotlib.patches import Rectangle
|
|||
|
|
|
|||
|
|
|
|||
|
|
def plot_contrast(app, contrast_data, test_type):
|
|||
|
|
"""绘制对比度测试结果 - 固定布局版本"""
|
|||
|
|
self = app
|
|||
|
|
|
|||
|
|
# 清空并重置
|
|||
|
|
self.contrast_ax.clear()
|
|||
|
|
self.contrast_ax.set_xlim(0, 1)
|
|||
|
|
self.contrast_ax.set_ylim(0, 1)
|
|||
|
|
self.contrast_ax.axis("off")
|
|||
|
|
|
|||
|
|
# 强制重置布局
|
|||
|
|
self.contrast_fig.subplots_adjust(
|
|||
|
|
left=0.02,
|
|||
|
|
right=0.98,
|
|||
|
|
top=0.90,
|
|||
|
|
bottom=0.02,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
max_lum = contrast_data["max_luminance"]
|
|||
|
|
min_lum = contrast_data["min_luminance"]
|
|||
|
|
contrast = contrast_data["contrast_ratio"]
|
|||
|
|
|
|||
|
|
# 确定等级和颜色
|
|||
|
|
if contrast >= 5000:
|
|||
|
|
grade, grade_color = "优秀", "#4CAF50"
|
|||
|
|
elif contrast >= 3000:
|
|||
|
|
grade, grade_color = "良好", "#8BC34A"
|
|||
|
|
elif contrast >= 1000:
|
|||
|
|
grade, grade_color = "合格", "#FFC107"
|
|||
|
|
else:
|
|||
|
|
grade, grade_color = "不合格", "#F44336"
|
|||
|
|
|
|||
|
|
test_type_name = self.get_test_type_name(test_type)
|
|||
|
|
|
|||
|
|
# ========== 顶部标题 - 统一格式 ==========
|
|||
|
|
self.contrast_fig.suptitle(
|
|||
|
|
f"{test_type_name} - 对比度测试",
|
|||
|
|
fontsize=12,
|
|||
|
|
y=0.98,
|
|||
|
|
fontweight="bold",
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# ========== 中央大对比度卡片 ==========
|
|||
|
|
center_card = Rectangle(
|
|||
|
|
(0.15, 0.48),
|
|||
|
|
0.70,
|
|||
|
|
0.32,
|
|||
|
|
transform=self.contrast_ax.transAxes,
|
|||
|
|
facecolor=grade_color,
|
|||
|
|
edgecolor="black",
|
|||
|
|
linewidth=2.5,
|
|||
|
|
alpha=0.15,
|
|||
|
|
)
|
|||
|
|
self.contrast_ax.add_patch(center_card)
|
|||
|
|
|
|||
|
|
# 对比度数值
|
|||
|
|
self.contrast_ax.text(
|
|||
|
|
0.5,
|
|||
|
|
0.65,
|
|||
|
|
f"{contrast:.0f} : 1",
|
|||
|
|
ha="center",
|
|||
|
|
va="center",
|
|||
|
|
fontsize=36,
|
|||
|
|
fontweight="bold",
|
|||
|
|
color=grade_color,
|
|||
|
|
transform=self.contrast_ax.transAxes,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 等级标签
|
|||
|
|
self.contrast_ax.text(
|
|||
|
|
0.5,
|
|||
|
|
0.51,
|
|||
|
|
f"等级: {grade}",
|
|||
|
|
ha="center",
|
|||
|
|
va="center",
|
|||
|
|
fontsize=12,
|
|||
|
|
fontweight="bold",
|
|||
|
|
color=grade_color,
|
|||
|
|
transform=self.contrast_ax.transAxes,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# ========== 两个信息卡片(缩小)==========
|
|||
|
|
card_width = 0.32
|
|||
|
|
card_height = 0.22
|
|||
|
|
card_y = 0.12
|
|||
|
|
|
|||
|
|
gap = 0.05
|
|||
|
|
total_width = card_width * 2 + gap
|
|||
|
|
start_x = (1 - total_width) / 2
|
|||
|
|
|
|||
|
|
cards_data = [
|
|||
|
|
{
|
|||
|
|
"x": start_x,
|
|||
|
|
"title": "白场亮度",
|
|||
|
|
"value": f"{max_lum:.2f}",
|
|||
|
|
"unit": "cd/m²",
|
|||
|
|
"color": "#E3F2FD",
|
|||
|
|
"edge_color": "#2196F3",
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
"x": start_x + card_width + gap,
|
|||
|
|
"title": "黑场亮度",
|
|||
|
|
"value": f"{min_lum:.4f}",
|
|||
|
|
"unit": "cd/m²",
|
|||
|
|
"color": "#F3E5F5",
|
|||
|
|
"edge_color": "#9C27B0",
|
|||
|
|
},
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
for card in cards_data:
|
|||
|
|
# 绘制卡片背景
|
|||
|
|
rect = Rectangle(
|
|||
|
|
(card["x"], card_y),
|
|||
|
|
card_width,
|
|||
|
|
card_height,
|
|||
|
|
transform=self.contrast_ax.transAxes,
|
|||
|
|
facecolor=card["color"],
|
|||
|
|
edgecolor=card["edge_color"],
|
|||
|
|
linewidth=2,
|
|||
|
|
)
|
|||
|
|
self.contrast_ax.add_patch(rect)
|
|||
|
|
|
|||
|
|
# 标题
|
|||
|
|
self.contrast_ax.text(
|
|||
|
|
card["x"] + card_width / 2,
|
|||
|
|
card_y + card_height - 0.03,
|
|||
|
|
card["title"],
|
|||
|
|
ha="center",
|
|||
|
|
va="top",
|
|||
|
|
fontsize=10,
|
|||
|
|
fontweight="bold",
|
|||
|
|
transform=self.contrast_ax.transAxes,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 数值
|
|||
|
|
self.contrast_ax.text(
|
|||
|
|
card["x"] + card_width / 2,
|
|||
|
|
card_y + card_height / 2,
|
|||
|
|
card["value"],
|
|||
|
|
ha="center",
|
|||
|
|
va="center",
|
|||
|
|
fontsize=16,
|
|||
|
|
fontweight="bold",
|
|||
|
|
transform=self.contrast_ax.transAxes,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 单位
|
|||
|
|
self.contrast_ax.text(
|
|||
|
|
card["x"] + card_width / 2,
|
|||
|
|
card_y + 0.03,
|
|||
|
|
card["unit"],
|
|||
|
|
ha="center",
|
|||
|
|
va="bottom",
|
|||
|
|
fontsize=9,
|
|||
|
|
color="gray",
|
|||
|
|
transform=self.contrast_ax.transAxes,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
self.contrast_canvas.draw()
|
|||
|
|
self.chart_notebook.select(3)
|