准备写论文,论文大纲和数据搞定
This commit is contained in:
57
generate_bars.py
Normal file
57
generate_bars.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Generate comparison bar chart.
|
||||
"""
|
||||
|
||||
import json
|
||||
import matplotlib
|
||||
|
||||
matplotlib.use("Agg")
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def load_statistics():
|
||||
with open("results/statistics.json", "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def main():
|
||||
stats = load_statistics()
|
||||
|
||||
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
|
||||
|
||||
algorithms = ["gradient", "flooding", "random"]
|
||||
colors = ["#2E86AB", "#E94F37", "#7D8491"]
|
||||
|
||||
metrics = [
|
||||
("pdr", "PDR (%)"),
|
||||
("airtime_usage_percent", "Airtime (%)"),
|
||||
("tx_per_success", "TX/Success"),
|
||||
]
|
||||
|
||||
for idx, (metric, label) in enumerate(metrics):
|
||||
ax = axes[idx]
|
||||
values = [stats[a][metric]["mean"] for a in algorithms]
|
||||
errors = [stats[a][metric]["ci_95"] for a in algorithms]
|
||||
|
||||
bars = ax.bar(
|
||||
algorithms, values, yerr=errors, color=colors, capsize=5, alpha=0.8
|
||||
)
|
||||
ax.set_ylabel(label, fontsize=11)
|
||||
ax.set_title(label, fontsize=12)
|
||||
ax.grid(True, alpha=0.3, axis="y")
|
||||
|
||||
# Add value labels
|
||||
for i, (bar, val, err) in enumerate(zip(bars, values, errors)):
|
||||
ax.text(
|
||||
i, val + err + 0.5, f"{val:.1f}", ha="center", va="bottom", fontsize=10
|
||||
)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig("figures/comparison_bar.pdf", dpi=300)
|
||||
plt.savefig("figures/comparison_bar.png", dpi=150)
|
||||
print("Saved: figures/comparison_bar.pdf")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user