Skip to content

Commit 560c655

Browse files
authored
Merge pull request #10 from calculquebec/rev/h26/chap2
Révision du chapitre 2
2 parents 64dd4d7 + 22e50f9 commit 560c655

1 file changed

Lines changed: 55 additions & 33 deletions

File tree

src/02-altair.ipynb

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,14 @@
624624
"lang": "fr"
625625
},
626626
"source": [
627-
"* **Colonnes temporaires** - Pour ajouter du bruit,\n",
628-
" on peut se créer des colonnes temporaires avec\n",
629-
" [`transform_calculate()`](https://altair-viz.github.io/user_guide/transform/calculate.html).\n",
630-
" Cependant, il faut spécifier explicitement\n",
631-
" [le type donnée](https://altair-viz.github.io/user_guide/encodings/index.html#encoding-data-types)."
627+
"* **Colonnes temporaires** - Pour ajouter du bruit, on peut se créer\n",
628+
" des colonnes temporaires avec [la méthode\n",
629+
" `transform_calculate()`](https://altair-viz.github.io/user_guide/transform/calculate.html)\n",
630+
" * Le calcul des valeurs se fait au moyen d'une [expression\n",
631+
" Vega](https://vega.github.io/vega/docs/expressions/)\n",
632+
" * Pour accéder aux colonnes existantes, on passe par l'objet `datum`\n",
633+
" * À l'encodage d'un canal, on doit spécifier explicitement [le type\n",
634+
" de données](https://altair-viz.github.io/user_guide/encodings/index.html#encoding-data-types)"
632635
]
633636
},
634637
{
@@ -638,11 +641,15 @@
638641
"lang": "en"
639642
},
640643
"source": [
641-
"* **Temporary columns** - To add some noise,\n",
642-
" we can create temporary columns with\n",
643-
" [`transform_calculate()`](https://altair-viz.github.io/user_guide/transform/calculate.html).\n",
644-
" Once done, we have to specify\n",
645-
" [the data type](https://altair-viz.github.io/user_guide/encodings/index.html#encoding-data-types)."
644+
"* **Temporary columns** - To add some noise, we can create temporary\n",
645+
" columns with [the `transform_calculate()`\n",
646+
" method](https://altair-viz.github.io/user_guide/transform/calculate.html)\n",
647+
" * The values are calculated using a [Vega\n",
648+
" expression](https://vega.github.io/vega/docs/expressions/)\n",
649+
" * To access the existing columns, we use the `datum` object\n",
650+
" * When encoding a channel, [the data\n",
651+
" type](https://altair-viz.github.io/user_guide/encodings/index.html#encoding-data-types)\n",
652+
" must be explicitly specified"
646653
]
647654
},
648655
{
@@ -840,16 +847,18 @@
840847
"### Exercice - Créer un graphique à barres\n",
841848
"À partir du DataFrame `surveys_complet`, faites afficher le\n",
842849
"décompte du nombre d'enregistrements pour chaque `plot_id`. Instructions :\n",
843-
"* Utilisez\n",
844-
" [`mark_bar()`](https://altair-viz.github.io/gallery/simple_bar_chart.html)\n",
845-
" pour générer\n",
846-
" [le graphique](https://altair-viz.github.io/gallery/simple_histogram.html)\n",
847-
"* Sur l'axe horizontal, spécifiez la variable `'plot_id'` et le\n",
848-
" [type `'ordinal'`](https://altair-viz.github.io/user_guide/encodings/#encoding-data-types)\n",
849-
"* Sur l'axe vertical, spécifiez `'count()'` comme variable pour que\n",
850-
" Altair fasse automatiquement le décompte, ce qui évite de passer\n",
851-
" par la méthode `groupby()` du DataFrame\n",
852-
"* Activez le canal `tooltip` avec `'count()'` pour avoir le décompte\n",
850+
"1. Utilisez [la méthode\n",
851+
" `mark_bar()`](https://altair-viz.github.io/gallery/simple_bar_chart.html)\n",
852+
" pour générer le graphique\n",
853+
" * Cette méthode donne accès à la fonction d'agrégation `'count()'`\n",
854+
" pour obtenir le décompte des enregistrements. Cela nous évite de\n",
855+
" devoir utiliser la méthode `groupby()` du DataFrame. [Voir un\n",
856+
" exemple ici](https://altair-viz.github.io/gallery/simple_histogram.html)\n",
857+
"2. Pour l'axe horizontal, spécifiez la variable `'plot_id'` et le\n",
858+
" [type `'ordinal'`](https://altair-viz.github.io/user_guide/encodings/#encoding-data-types)\n",
859+
"3. Pour l'axe vertical, spécifiez `'count()'`\n",
860+
"4. Activez le canal `tooltip` pour voir le décompte au passage de la\n",
861+
" souris\n",
853862
"\n",
854863
"(6 min.)"
855864
]
@@ -864,15 +873,18 @@
864873
"### Exercise - Create a bar chart\n",
865874
"From the `surveys_complete` DataFrame, create an histogram that\n",
866875
"shows the count of records for each `plot_id`. Instructions:\n",
867-
"* Use\n",
868-
" [`mark_bar()`](https://altair-viz.github.io/gallery/simple_bar_chart.html)\n",
869-
" to generate the\n",
870-
" [chart](https://altair-viz.github.io/gallery/simple_histogram.html)\n",
871-
"* For the X axis, specify the `'plot_id'` field and the\n",
872-
" [`'ordinal'` type](https://altair-viz.github.io/user_guide/encodings/#encoding-data-types)\n",
873-
"* For the Y axis, specify `'count()'` as a temporary field computed\n",
874-
" automatically by Altair, which saves us from using `groupby()`\n",
875-
"* Activate the `tooltip` channel with `'count()'`\n",
876+
"1. Use the [`mark_bar()`\n",
877+
" method](https://altair-viz.github.io/gallery/simple_bar_chart.html)\n",
878+
" to generate the chart\n",
879+
" * This method provides access to the `'count()'` aggregation\n",
880+
" function to obtain the count of records. This saves us from using\n",
881+
" `groupby()`. [See an example\n",
882+
" here](https://altair-viz.github.io/gallery/simple_histogram.html)\n",
883+
"2. For the X axis, specify the `'plot_id'` field and the [`'ordinal'`\n",
884+
" type](https://altair-viz.github.io/user_guide/encodings/#encoding-data-types)\n",
885+
"3. For the Y axis, specify `'count()'`\n",
886+
"4. Activate the `tooltip` channel to see the count when moving the\n",
887+
" mouse\n",
876888
"\n",
877889
"(6 min.)"
878890
]
@@ -892,7 +904,9 @@
892904
"alt.Chart(surveys_complet).mark_bar().encode(\n",
893905
" x=alt.X('plot_id').type('ordinal'),\n",
894906
" y=alt.Y('count()'),\n",
895-
" tooltip=['count()'],\n",
907+
" tooltip=[\n",
908+
" alt.Tooltip('count()', title=\"Nombre d'enregistrements\")\n",
909+
" ],\n",
896910
")"
897911
]
898912
},
@@ -911,7 +925,9 @@
911925
"###(surveys_complet)###\n",
912926
" ###('plot_id').type('ordinal'),\n",
913927
" ###('count()'),\n",
914-
" ###['count()'],\n",
928+
" ###[\n",
929+
" alt.Tooltip('count()', title=\"Nombre d'enregistrements\")\n",
930+
" ],\n",
915931
")"
916932
]
917933
},
@@ -930,7 +946,9 @@
930946
"alt.Chart(surveys_complete).mark_bar().encode(\n",
931947
" x=alt.X('plot_id').type('ordinal'),\n",
932948
" y=alt.Y('count()'),\n",
933-
" tooltip=['count()'],\n",
949+
" tooltip=[\n",
950+
" alt.Tooltip('count()', title='Number of records')\n",
951+
" ],\n",
934952
")"
935953
]
936954
},
@@ -949,7 +967,9 @@
949967
"###(surveys_complete)###\n",
950968
" ###('plot_id').type('ordinal'),\n",
951969
" ###('count()'),\n",
952-
" ###['count()'],\n",
970+
" ###[\n",
971+
" alt.Tooltip('count()', title='Number of records')\n",
972+
" ],\n",
953973
")"
954974
]
955975
},
@@ -982,6 +1002,7 @@
9821002
" * Catégories discrètes : `'nominal'`, `'var:N'`\n",
9831003
" * Dates et heures : `'temporal'`, `'var:T'`\n",
9841004
" * `tooltip=['varX', 'varY', ...]`\n",
1005+
" * `alt.Tooltip('count()', title=\"Nom de l'agrégation\")`\n",
9851006
"* **Autres propriétés du graphique**\n",
9861007
" * `graphique.interactive()`\n",
9871008
"* **Sauvegarde**\n",
@@ -1019,6 +1040,7 @@
10191040
" * Discrete unordered category: `'nominal'`, `'var:N'`\n",
10201041
" * Time or date value: `'temporal'`, `'var:T'`\n",
10211042
" * `tooltip=['field_name1', 'field_name2', 'field_name3', ...]`\n",
1043+
" * `alt.Tooltip('count()', title='Aggregation name')`\n",
10221044
"* **Other properties of the chart**\n",
10231045
" * `chart.interactive()`\n",
10241046
"* **Saving the figure**\n",

0 commit comments

Comments
 (0)