import matplotlib.pyplot as plt
import pandas as pd

# 数据准备
data = {
    'digg': {
        'η/n': [0.05, 0.1, 0.15, 0.2, 0.25],
        'AdaMBTS': [5.93, 13.51, 15.52, 15.78, 17.82],
        'AdaMBTS-LB': [3.46, 6.55, 6.93, 6.72, 6.8],
        'SpeedUp': [1.713873, 2.062595, 2.239538, 2.348214, 2.620588]
    },
    'flixster': {
        'η/n': [0.1, 0.2, 0.3, 0.4, 0.5],
        'AdaMBTS': [31.83, 49.5, 48.48, 50.03, 65.94],
        'AdaMBTS-LB': [15.52, 23.1, 20.61, 20.79, 23.8],
        'SpeedUp': [2.050902, 2.142857, 2.352256, 2.406445, 2.770588]
    },
    'twitter': {
        'η/n': [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35],
        'AdaMBTS': [29.25, 30.16, 27.54, 36.94, 38.58, 36.64, 28.38],
        'AdaMBTS-LB': [26.44, 23.66, 21.56, 23.23, 23.62, 20.86, 14.84],
        'SpeedUp': [1.106278, 1.274725, 1.277365, 1.590185, 1.633362, 1.756472, 1.912399]
    }
}



# 创建画布和子图（1行3列）
fig, axes = plt.subplots(3, 1, figsize=(6, 5))
plt.subplots_adjust(wspace=0.3)

# 新颜色设置
color_ambts = '#000000'  # 黑色
color_lb = '#ff0000'     # 红色
color_speedup = '#2ca02c' # 速度值保持绿色

for ax, (dataset, values) in zip(axes, data.items()):
    df = pd.DataFrame(values)
    
    # 绘制主曲线
    ambts_line = ax.plot(df['η/n'], df['AdaMBTS'], 
                        marker='o', 
                        color=color_ambts, 
                        label='AdaMBTS')
    
    ax.plot(df['η/n'], df['AdaMBTS-LB'], 
           marker='s', 
           color=color_lb, 
           label='AdaMBTS-LB')
    
    # 添加速度标注（在AdaMBTS点上方）
    for (x, y_ambts), speedup in zip(zip(df['η/n'], df['AdaMBTS']), df['SpeedUp']):
        ax.text(x,               # x坐标相同
                y_ambts + 1.5,   # 在AdaMBTS点上偏移1.5单位
                f'{speedup:.2f}x',# 保留两位小数
                ha='center',
                va='bottom',
                #color=color_speedup,
                fontsize=9,
                rotation=30,
                fontstyle='italic')
    
    ax.set_xlabel('η/n', fontsize=10)
    ax.set_ylabel('平均每轮次运行时间/s', fontsize=10)
    #ax.set_title(dataset.capitalize(), fontsize=12)
    ax.set
    ax.grid(True, linestyle='--', alpha=0.6)
    
    # 简化图例（仅保留两条曲线）
    if dataset == 'digg':
        ax.legend(loc='upper center', fontsize=8, ncol=2, bbox_to_anchor=(0.5, 1.2))
    #ax.legend(loc='upper left', fontsize=8)

plt.tight_layout()
plt.show()



plt.savefig('social_net.png')