|
624 | 624 | "lang": "fr" |
625 | 625 | }, |
626 | 626 | "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)" |
632 | 635 | ] |
633 | 636 | }, |
634 | 637 | { |
|
638 | 641 | "lang": "en" |
639 | 642 | }, |
640 | 643 | "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" |
646 | 653 | ] |
647 | 654 | }, |
648 | 655 | { |
|
840 | 847 | "### Exercice - Créer un graphique à barres\n", |
841 | 848 | "À partir du DataFrame `surveys_complet`, faites afficher le\n", |
842 | 849 | "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", |
853 | 862 | "\n", |
854 | 863 | "(6 min.)" |
855 | 864 | ] |
|
864 | 873 | "### Exercise - Create a bar chart\n", |
865 | 874 | "From the `surveys_complete` DataFrame, create an histogram that\n", |
866 | 875 | "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", |
876 | 888 | "\n", |
877 | 889 | "(6 min.)" |
878 | 890 | ] |
|
892 | 904 | "alt.Chart(surveys_complet).mark_bar().encode(\n", |
893 | 905 | " x=alt.X('plot_id').type('ordinal'),\n", |
894 | 906 | " y=alt.Y('count()'),\n", |
895 | | - " tooltip=['count()'],\n", |
| 907 | + " tooltip=[\n", |
| 908 | + " alt.Tooltip('count()', title=\"Nombre d'enregistrements\")\n", |
| 909 | + " ],\n", |
896 | 910 | ")" |
897 | 911 | ] |
898 | 912 | }, |
|
911 | 925 | "###(surveys_complet)###\n", |
912 | 926 | " ###('plot_id').type('ordinal'),\n", |
913 | 927 | " ###('count()'),\n", |
914 | | - " ###['count()'],\n", |
| 928 | + " ###[\n", |
| 929 | + " alt.Tooltip('count()', title=\"Nombre d'enregistrements\")\n", |
| 930 | + " ],\n", |
915 | 931 | ")" |
916 | 932 | ] |
917 | 933 | }, |
|
930 | 946 | "alt.Chart(surveys_complete).mark_bar().encode(\n", |
931 | 947 | " x=alt.X('plot_id').type('ordinal'),\n", |
932 | 948 | " y=alt.Y('count()'),\n", |
933 | | - " tooltip=['count()'],\n", |
| 949 | + " tooltip=[\n", |
| 950 | + " alt.Tooltip('count()', title='Number of records')\n", |
| 951 | + " ],\n", |
934 | 952 | ")" |
935 | 953 | ] |
936 | 954 | }, |
|
949 | 967 | "###(surveys_complete)###\n", |
950 | 968 | " ###('plot_id').type('ordinal'),\n", |
951 | 969 | " ###('count()'),\n", |
952 | | - " ###['count()'],\n", |
| 970 | + " ###[\n", |
| 971 | + " alt.Tooltip('count()', title='Number of records')\n", |
| 972 | + " ],\n", |
953 | 973 | ")" |
954 | 974 | ] |
955 | 975 | }, |
|
982 | 1002 | " * Catégories discrètes : `'nominal'`, `'var:N'`\n", |
983 | 1003 | " * Dates et heures : `'temporal'`, `'var:T'`\n", |
984 | 1004 | " * `tooltip=['varX', 'varY', ...]`\n", |
| 1005 | + " * `alt.Tooltip('count()', title=\"Nom de l'agrégation\")`\n", |
985 | 1006 | "* **Autres propriétés du graphique**\n", |
986 | 1007 | " * `graphique.interactive()`\n", |
987 | 1008 | "* **Sauvegarde**\n", |
|
1019 | 1040 | " * Discrete unordered category: `'nominal'`, `'var:N'`\n", |
1020 | 1041 | " * Time or date value: `'temporal'`, `'var:T'`\n", |
1021 | 1042 | " * `tooltip=['field_name1', 'field_name2', 'field_name3', ...]`\n", |
| 1043 | + " * `alt.Tooltip('count()', title='Aggregation name')`\n", |
1022 | 1044 | "* **Other properties of the chart**\n", |
1023 | 1045 | " * `chart.interactive()`\n", |
1024 | 1046 | "* **Saving the figure**\n", |
|
0 commit comments