migration to altair plots

This commit is contained in:
2026-01-28 21:01:39 +01:00
parent 3f929d93fd
commit 0485f991d2
5 changed files with 601 additions and 828 deletions

View File

@@ -42,7 +42,7 @@ def _(JPMCSurvey, QSF_FILE, RESULTS_FILE):
return S, data_all
@app.cell
@app.cell(hide_code=True)
def _(Path, RESULTS_FILE, data_all, mo):
mo.md(f"""
# Load Data
@@ -68,12 +68,6 @@ def _(check_progress, data_all, duration_validation, mo):
return
@app.cell
def _(data_all, duration_validation):
duration_validation(data_all)
return
@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
@@ -120,8 +114,9 @@ def _(S, mo):
return (filter_form,)
@app.cell
@app.cell(hide_code=True)
def _(S, data_all, filter_form, mo):
mo.stop(filter_form.value is None, mo.md("**Please submit filter above to proceed**"))
_d = S.filter_data(data_all, age=filter_form.value['age'], gender=filter_form.value['gender'], income=filter_form.value['income'], ethnicity=filter_form.value['ethnicity'], consumer=filter_form.value['consumer'])
# Stop execution and prevent other cells from running if no data is selected
@@ -162,7 +157,7 @@ def _(S, char_rank, mo):
### 1. Which character personality is ranked best?
{mo.ui.plotly(S.plot_top3_ranking_distribution(char_rank, x_label='Character Personality', width=1000))}
{mo.ui.altair_chart(S.plot_top3_ranking_distribution(char_rank, x_label='Character Personality'))}
""")
return
@@ -173,7 +168,7 @@ def _(S, char_rank, mo):
### 2. Which character personality is ranked 1st the most?
{mo.ui.plotly(S.plot_most_ranked_1(char_rank, title="Most Popular Character<br>(Number of Times Ranked 1st)", x_label='Character Personality', width=1000))}
{mo.ui.altair_chart(S.plot_most_ranked_1(char_rank, title="Most Popular Character<br>(Number of Times Ranked 1st)", x_label='Character Personality', width=1000))}
""")
return
@@ -186,7 +181,7 @@ def _(S, calculate_weighted_ranking_scores, char_rank, mo):
### 3. Which character personality most popular based on weighted scores?
{mo.ui.plotly(S.plot_weighted_ranking_score(char_rank_weighted, title="Most Popular Character - Weighted Popularity Score<br>(1st=3pts, 2nd=2pts, 3rd=1pt)", x_label='Voice', width=1000))}
{mo.ui.altair_chart(S.plot_weighted_ranking_score(char_rank_weighted, title="Most Popular Character - Weighted Popularity Score<br>(1st=3pts, 2nd=2pts, 3rd=1pt)", x_label='Voice', width=1000))}
""")
return
@@ -211,7 +206,7 @@ def _(S, mo, v_18_8_3):
mo.md(f"""
### Which 8 voices are chosen the most out of 18?
{mo.ui.plotly(S.plot_voice_selection_counts(v_18_8_3, height=500, width=1000))}
{mo.ui.altair_chart(S.plot_voice_selection_counts(v_18_8_3, height=500, width=1000))}
""")
return
@@ -223,7 +218,7 @@ def _(S, mo, v_18_8_3):
How many times does each voice end up in the top 3? ( this is based on the survey question where participants need to choose 3 out of the earlier selected 8 voices. So how often each of the 18 stimuli ended up in participants Top 3, after they first selected 8 out of 18.
{mo.ui.plotly(S.plot_top3_selection_counts(v_18_8_3, height=500, width=1000))}
{mo.ui.altair_chart(S.plot_top3_selection_counts(v_18_8_3, height=500, width=1000))}
""")
return
@@ -242,7 +237,7 @@ def _(S, mo, top3_voices):
(not best 3 out of 8 question)
{mo.ui.plotly(S.plot_ranking_distribution(top3_voices, x_label='Voice', width=1000))}
{mo.ui.altair_chart(S.plot_ranking_distribution(top3_voices, x_label='Voice', width=1000))}
""")
return
@@ -254,7 +249,7 @@ def _(S, mo, top3_voices_weighted):
- E.g. 1 point for place 3. 2 points for place 2 and 3 points for place 1. The voice with most points is ranked best.
Distribution of the rankings for each voice:
{mo.ui.plotly(S.plot_weighted_ranking_score(top3_voices_weighted, title="Most Popular Voice - Weighted Popularity Score<br>(1st = 3pts, 2nd = 2pts, 3rd = 1pt)", height=500, width=1000))}
{mo.ui.altair_chart(S.plot_weighted_ranking_score(top3_voices_weighted, title="Most Popular Voice - Weighted Popularity Score<br>(1st = 3pts, 2nd = 2pts, 3rd = 1pt)", height=500, width=1000))}
""")
return
@@ -266,7 +261,7 @@ def _(S, mo, top3_voices):
(not always the voice with most points)
{mo.ui.plotly(S.plot_most_ranked_1(top3_voices, title="Most Popular Voice<br>(Number of Times Ranked 1st)", x_label='Voice', width=1000))}
{mo.ui.altair_chart(S.plot_most_ranked_1(top3_voices, title="Most Popular Voice<br>(Number of Times Ranked 1st)", x_label='Voice', width=1000))}
""")
return
@@ -307,7 +302,7 @@ def _(S, mo, pl, ss_long):
content += f"""
### {i+1}) {trait.replace(":", "")}
{mo.ui.plotly(S.plot_speaking_style_trait_scores(trait_d, title=trait.replace(":", ""), height=550))}
{mo.ui.altair_chart(S.plot_speaking_style_trait_scores(trait_d, title=trait.replace(":", ""), height=550))}
"""
mo.md(content)
@@ -334,7 +329,7 @@ def _(S, mo, vscales):
mo.md(f"""
### How does each voice score on a scale from 1-10?
{mo.ui.plotly(S.plot_average_scores_with_counts(vscales, x_label='Voice', width=1000))}
{mo.ui.altair_chart(S.plot_average_scores_with_counts(vscales, x_label='Voice', width=1000))}
""")
return
@@ -404,7 +399,7 @@ def _(S, SPEAKING_STYLES, joined_df, mo):
_content += f"""
#### Speaking Style **{style}**:
{mo.ui.plotly(fig)}
{mo.ui.altair_chart(fig)}
"""
mo.md(_content)
@@ -469,7 +464,7 @@ def _(S, SPEAKING_STYLES, df_style, mo, top3_voices, utils):
#### Speaking Style **{_style}**:
{mo.ui.plotly(_fig)}
{mo.ui.altair_chart(_fig)}
"""