juhoinkinen commited on
Commit
7234b29
·
unverified ·
1 Parent(s): cd94882

Format plot to use horizontal bars and resemble Annif Web UI

Browse files
Files changed (1) hide show
  1. app.py +31 -5
app.py CHANGED
@@ -55,14 +55,40 @@ def process(image, project_num: int, lang: str = "eng"):
55
  labels = [res['label'] for res in results]
56
  scores = [res['score'] for res in results]
57
 
58
- # Create a bar plot
59
- fig = go.Figure(data=[go.Bar(x=labels, y=scores)])
 
 
 
 
 
 
 
 
 
 
 
60
  fig.update_layout(
61
- title="Annif Suggestion Scores",
62
- xaxis_title="Labels",
63
- yaxis_title="Scores"
 
 
 
 
 
 
 
 
 
 
 
 
64
  )
65
 
 
 
 
66
  return text, fig
67
  except Exception as e:
68
  return str(e), None
 
55
  labels = [res['label'] for res in results]
56
  scores = [res['score'] for res in results]
57
 
58
+ # Create a horizontal bar plot
59
+ fig = go.Figure()
60
+
61
+ # Add bars
62
+ fig.add_trace(go.Bar(
63
+ y=labels[::-1], # Reverse order to have highest score at top
64
+ x=scores[::-1],
65
+ orientation='h',
66
+ marker_color='lightblue',
67
+ width=0.6, # Adjust bar width
68
+ ))
69
+
70
+ # Customize the layout
71
  fig.update_layout(
72
+ title="SUGGESTED SUBJECTS",
73
+ title_font=dict(size=16, color='black', family='Arial, sans-serif'),
74
+ xaxis=dict(
75
+ title=None,
76
+ showticklabels=False,
77
+ showgrid=False,
78
+ zeroline=False,
79
+ ),
80
+ yaxis=dict(
81
+ title=None,
82
+ tickfont=dict(size=12, color='black', family='Arial, sans-serif'),
83
+ ),
84
+ margin=dict(l=10, r=10, t=40, b=10),
85
+ height=400,
86
+ plot_bgcolor='white',
87
  )
88
 
89
+ # Remove the plotly logo
90
+ fig.update_layout(showlegend=False)
91
+
92
  return text, fig
93
  except Exception as e:
94
  return str(e), None