26 lines
758 B
Python
26 lines
758 B
Python
import json
|
|
import matplotlib.pyplot as plt
|
|
|
|
# 读取 json 文件
|
|
with open('real.json', 'r') as f:
|
|
data = json.load(f)
|
|
|
|
intervals = data['intervals']
|
|
times = [i['sum']['start'] for i in intervals]
|
|
bandwidth = [i['sum']['bits_per_second'] / 1e6 for i in intervals] # 转为 Mbps
|
|
loss = [i['sum']['lost_percent'] for i in intervals]
|
|
|
|
# 绘图
|
|
fig, ax1 = plt.subplots()
|
|
|
|
ax1.set_xlabel('Time (s)')
|
|
ax1.set_ylabel('Bandwidth (Mbps)', color='tab:blue')
|
|
ax1.plot(times, bandwidth, color='tab:blue', label='Bandwidth')
|
|
ax1.set_ylim(0, 25) # 20M带宽建议坐标上限设为25
|
|
|
|
ax2 = ax1.twinx()
|
|
ax2.set_ylabel('Loss (%)', color='tab:red')
|
|
ax2.plot(times, loss, color='tab:red', linestyle='--', label='Loss %')
|
|
|
|
plt.title('iperf3 UDP 20M Pull Test')
|
|
plt.show() |