InnerI commited on
Commit
328f62b
·
verified ·
1 Parent(s): de8a5bd

Create utils_viz.py

Browse files
Files changed (1) hide show
  1. utils_viz.py +17 -0
utils_viz.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # utils_viz.py
2
+ import io
3
+ import matplotlib.pyplot as plt
4
+
5
+ def bar_topk(top_rows):
6
+ labels = [r["name"] for r in top_rows]
7
+ vals = [r["score"] for r in top_rows]
8
+ fig, ax = plt.subplots(figsize=(7,3))
9
+ ax.barh(labels[::-1], vals[::-1])
10
+ ax.set_xlabel("Score")
11
+ ax.set_xlim(0,100)
12
+ fig.tight_layout()
13
+ bio = io.BytesIO()
14
+ fig.savefig(bio, format="png", dpi=160, bbox_inches="tight")
15
+ plt.close(fig)
16
+ bio.seek(0)
17
+ return bio