speaking style trait scores
This commit is contained in:
35
plots.py
35
plots.py
@@ -768,7 +768,7 @@ def plot_speaking_style_trait_scores(
|
||||
pl.col("score").mean().alias("mean_score"),
|
||||
pl.col("score").count().alias("count")
|
||||
])
|
||||
.sort("mean_score", descending=True) # Descending for Left-to-Right
|
||||
.sort("mean_score", descending=False) # Ascending for display bottom-to-top
|
||||
)
|
||||
|
||||
# Attempt to extract anchors from DF if not provided
|
||||
@@ -795,33 +795,36 @@ def plot_speaking_style_trait_scores(
|
||||
fig = go.Figure()
|
||||
|
||||
fig.add_trace(go.Bar(
|
||||
x=stats["Voice"], # X is Voice
|
||||
y=stats["mean_score"], # Y is Score
|
||||
y=stats["Voice"], # Y is Voice
|
||||
x=stats["mean_score"], # X is Score
|
||||
orientation='h',
|
||||
text=stats["count"],
|
||||
textposition='inside',
|
||||
textangle=0,
|
||||
textfont=dict(size=16, color='white'),
|
||||
texttemplate='%{text}', # Count on bar
|
||||
marker_color=ColorPalette.PRIMARY,
|
||||
hovertemplate='<b>%{x}</b><br>Average: %{y:.2f}<br>Count: %{text}<extra></extra>'
|
||||
hovertemplate='<b>%{y}</b><br>Average: %{x:.2f}<br>Count: %{text}<extra></extra>'
|
||||
))
|
||||
|
||||
# Add annotations for anchors
|
||||
annotations = []
|
||||
|
||||
# Place anchors on the right side
|
||||
# Place anchors at the bottom
|
||||
if left_anchor:
|
||||
annotations.append(dict(
|
||||
xref='paper', yref='y',
|
||||
x=1.01, y=1,
|
||||
xanchor='left', yanchor='middle',
|
||||
xref='x', yref='paper',
|
||||
x=1, y=-0.2, # Below axis
|
||||
xanchor='left', yanchor='top',
|
||||
text=f"<b>1: {left_anchor.split('|')[0]}</b>",
|
||||
showarrow=False,
|
||||
font=dict(size=10, color='gray')
|
||||
))
|
||||
if right_anchor:
|
||||
annotations.append(dict(
|
||||
xref='paper', yref='y',
|
||||
x=1.01, y=5,
|
||||
xanchor='left', yanchor='middle',
|
||||
xref='x', yref='paper',
|
||||
x=5, y=-0.2, # Below axis
|
||||
xanchor='right', yanchor='top',
|
||||
text=f"<b>5: {right_anchor.split('|')[0]}</b>",
|
||||
showarrow=False,
|
||||
font=dict(size=10, color='gray')
|
||||
@@ -832,21 +835,21 @@ def plot_speaking_style_trait_scores(
|
||||
text=f"{title}<br><sub>{trait_description}</sub><br><sub>(Numbers on bars indicate respondent count)</sub>",
|
||||
y=0.92
|
||||
),
|
||||
xaxis_title="Voice",
|
||||
yaxis_title="Average Score (1-5)",
|
||||
xaxis_title="Average Score (1-5)",
|
||||
yaxis_title="Voice",
|
||||
height=height,
|
||||
width=width,
|
||||
plot_bgcolor=ColorPalette.BACKGROUND,
|
||||
yaxis=dict(
|
||||
xaxis=dict(
|
||||
range=[1, 5],
|
||||
showgrid=True,
|
||||
gridcolor=ColorPalette.GRID,
|
||||
zeroline=False
|
||||
),
|
||||
xaxis=dict(
|
||||
yaxis=dict(
|
||||
showgrid=False
|
||||
),
|
||||
margin=dict(r=150),
|
||||
margin=dict(b=120),
|
||||
annotations=annotations,
|
||||
font=dict(size=11)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user