Skip to content

Commit

Permalink
Bonifier le tooltip des bar-plot
Browse files Browse the repository at this point in the history
  • Loading branch information
plstonge committed Jan 29, 2025
1 parent a9bcc0c commit bea7c6c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/05-altair.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@
"* Sur l'axe vertical, spécifiez `'count()'` comme variable pour que\n",
" Altair fasse automatiquement le décompte, ce qui évite de passer\n",
" par la méthode `groupby()` du DataFrame\n",
"* Activez le canal `tooltip` avec `'count()'` pour avoir le décompte\n",
"\n",
"(4 min.)"
]
Expand All @@ -574,6 +575,7 @@
" [`'ordinal'` type](https://altair-viz.github.io/user_guide/encodings/#encoding-data-types)\n",
"* For the Y axis, specify `'count()'` as a temporary field computed\n",
" automatically by Altair, which saves us from using `groupby()`\n",
"* Activate the `tooltip` channel with `'count()'`\n",
"\n",
"(4 min.)"
]
Expand All @@ -593,6 +595,7 @@
"alt.Chart(surveys_complet).mark_bar().encode(\n",
" x=alt.X('plot_id').type('ordinal'),\n",
" y=alt.Y('count()'),\n",
" tooltip=['count()'],\n",
")"
]
},
Expand All @@ -611,6 +614,7 @@
"###(surveys_complet)###\n",
" ###('plot_id').type('ordinal'),\n",
" ###('count()'),\n",
" ###['count()'],\n",
")"
]
},
Expand All @@ -629,6 +633,7 @@
"alt.Chart(surveys_complete).mark_bar().encode(\n",
" x=alt.X('plot_id').type('ordinal'),\n",
" y=alt.Y('count()'),\n",
" tooltip=['count()'],\n",
")"
]
},
Expand All @@ -647,6 +652,7 @@
"###(surveys_complete)###\n",
" ###('plot_id').type('ordinal'),\n",
" ###('count()'),\n",
" ###['count()'],\n",
")"
]
},
Expand Down Expand Up @@ -976,8 +982,7 @@
" `'sex'`. La méthode `.scale()` permet ensuite d'associer les valeurs\n",
" de domaine `'F'` et `'M'` aux couleurs `'orange'` et `'green'`.\n",
" Voir [un exemple ici](https://altair-viz.github.io/user_guide/customization.html#color-domain-and-range)\n",
"* Activez le canal `tooltip` avec `'count()'` pour avoir le décompte\n",
" par sexe\n",
"* Dans le canal `tooltip`, ajoutez `'sex'` au début de la liste\n",
"\n",
"(4 min.)"
]
Expand All @@ -996,8 +1001,7 @@
" The `.scale()` method can then associate domain values `'F'`\n",
" and `'M'` to colors `'orange'` and `'green'`, respectively.\n",
" See [an example here](https://altair-viz.github.io/user_guide/customization.html#color-domain-and-range)\n",
"* Activate the `tooltip` channel with\n",
" `'count()'` in order to get the count by sex\n",
"* In the `tooltip` channel, add `'sex'` at the beginning of the list\n",
"\n",
"(4 min.)"
]
Expand All @@ -1021,7 +1025,7 @@
" domain=['F', 'M'],\n",
" range=['orange', 'green'],\n",
" ),\n",
" tooltip=['count()'],\n",
" tooltip=['sex', 'count()'],\n",
")"
]
},
Expand All @@ -1044,7 +1048,7 @@
" ###=['F', 'M'],\n",
" ###=['orange', 'green'],\n",
" ),\n",
" ###['count()'],\n",
" tooltip=[###, 'count()'],\n",
")"
]
},
Expand All @@ -1067,7 +1071,7 @@
" domain=['F', 'M'],\n",
" range=['orange', 'green'],\n",
" ),\n",
" tooltip=['count()'],\n",
" tooltip=['sex', 'count()'],\n",
")"
]
},
Expand All @@ -1090,7 +1094,7 @@
" ###=['F', 'M'],\n",
" ###=['orange', 'green'],\n",
" ),\n",
" ###['count()'],\n",
" tooltip=[###, 'count()'],\n",
")"
]
},
Expand Down

0 comments on commit bea7c6c

Please sign in to comment.