1.服务框架支持

wait

2.相关工具制作

2.1 生涯进度图生成

用于本站点关于页面生涯图生成,可修改参数调整。

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib
from datetime import datetime  # 用于获取当前年份


# 解决字体乱码问题
matplotlib.rcParams['font.sans-serif'] = ['KaiTi']  # 使用楷体
matplotlib.rcParams['axes.unicode_minus'] = False  # 解决负号问题


def draw_career_timeline(main_events, sub_events, output_file="生涯进度图.png"):
    fig, ax = plt.subplots(figsize=(8, 4))
    ax.set_xlim(0, 100)  # X轴范围
    ax.set_ylim(-20, 40)  # Y轴范围, 调整至40+较适配本站
    ax.axis("off")  # 隐藏坐标轴

    # 将 "now" 替换为当前年份
    current_year = datetime.now().year
    main_events = [
        (start, current_year if end == "now" else end, label, color)
        for start, end, label, color in main_events
    ]
    sub_events = [
        (start, current_year if end == "now" else end, label, color)
        for start, end, label, color in sub_events
    ]

    # 计算时间轴的比例
    min_year = min(event[0] for event in main_events)  # 最小年份
    max_year = max(event[1] for event in main_events)  # 最大年份
    total_duration = max_year - min_year  # 总时间跨度

    def scale_time(year):
        """将年份映射到 X 轴坐标"""
        return (year - min_year) / total_duration * 80 + 10  # 映射到 10-90 之间

    # 绘制主进度条
    for i, (start, end, label, color) in enumerate(main_events):
        x_start = scale_time(start)  # 起始年份的 X 坐标
        x_end = scale_time(end)  # 结束年份的 X 坐标
        width = x_end - x_start  # 进度条宽度
        # 绘制圆角矩形
        rect = patches.FancyBboxPatch(
            (x_start, 0), width, 6, boxstyle="round,pad=0.5,rounding_size=2.5", facecolor=color, edgecolor="none")
        ax.add_patch(rect)
        # 在矩形中间添加标签
        ax.text(x_start + width / 2, 3, label, ha='center', va='center', fontsize=12, color='white', fontweight='bold')
        # 在首尾添加年份标记
        if i == 0:  # 第一个主事件,标记起始年份
            ax.text(x_start, -2, str(start), ha='center', va='top', fontsize=14, color='black')
        # 标记结束年份(包括中间事件的结束年份)
        ax.text(x_end, -2, "现在" if end == current_year else str(end), ha='center', va='top', fontsize=14, color='black')

    # 绘制子进度条(交替放置在上方或下方)
    for i, (start, end, label, color) in enumerate(sub_events):
        x_start = scale_time(start)  # 起始年份的 X 坐标
        x_end = scale_time(end)  # 结束年份的 X 坐标
        width = x_end - x_start  # 进度条宽度
        y_offset = 10 if i % 2 == 0 else -8  # 交替放置在上方或下方
        # 绘制圆角矩形
        rect = patches.FancyBboxPatch(
            (x_start, y_offset), width, 4, boxstyle="round,pad=0.2,rounding_size=1.6", facecolor=color, edgecolor="none")
        ax.add_patch(rect)
        # 在矩形中间添加标签
        ax.text(x_start + width / 2, y_offset + 2, label, ha='center', va='center', fontsize=10, color='white', fontweight='bold')

    # 添加时间基线
    ax.plot([8, 92], [0, 0], color='#E0E0E0', lw=2, alpha=0.8, zorder=0)
    # 保存图片(去掉边框)
    plt.savefig(output_file, dpi=300, bbox_inches='tight', pad_inches=0, transparent=True)
    # plt.show()


if __name__ == "__main__":
    main_events = [
        (2021, "now", "Student", "#57bd6a")
    ]

    sub_events = [
        (2022, 2023, "DBAPPSecurity", "#cc0213"),
        (2023, 2024, "Lianlian", "#1985ff"),
        (2024, "now", "ThreatBook", "#9C27B0"),
    ]

    draw_career_timeline(main_events, sub_events)

生成示例:

生涯进度图示例.png