import matplotlib.pyplot as plt # 1. 准备数据 orders = ["1", "2", "3", "4", "5"] intensities = [1.000, 0.309, 0.0075, 0.0381, 0.0359] # 2. 设置中文字体和图形大小 plt.rcParams["font.sans-serif"] = ["SimHei", "Arial Unicode MS", "sans-serif"] plt.rcParams["axes.unicode_minus"] = False plt.rcParams["mathtext.fontset"] = "cm" # 使用 LaTeX 风格的数学字体 fig, ax = plt.subplots(figsize=(8, 4), dpi=150) # 3. 绘制柱状图 bars = ax.bar(orders, intensities, color="#4A5568", edgecolor="black", width=0.6) # 4. 设置坐标轴和样式 ax.set_title("级次与相对强度关系", fontsize=14, pad=15) ax.set_xlabel("m", fontsize=12) # 【核心修改点】加上 r 前缀和 $ 符号 ax.set_ylabel(r"$(I_m / I_1)$", fontsize=12, rotation=0, labelpad=25) # 5. 在柱子上方添加数值标签 for bar in bars: yval = bar.get_height() ax.text( bar.get_x() + bar.get_width() / 2, yval + 0.02, f"{yval:.4f}" if yval < 0.1 else f"{yval:.3f}", ha="center", va="bottom", fontsize=10, ) # 6. 优化视觉呈现 ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) ax.set_ylim(0, 1.2) plt.tight_layout() plt.show()