Skip to content

Commit

Permalink
Barres côte à côte dans les bar-charts
Browse files Browse the repository at this point in the history
  • Loading branch information
plstonge committed Jan 29, 2025
1 parent 3e59dcc commit 9f599b1
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 42 deletions.
10 changes: 5 additions & 5 deletions en/02-selection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@
"lang": "en"
},
"source": [
"`2`. Create a stacked bar plot of average weight by site\n",
"with male vs female values stacked for each site (`plot_id`).\n",
"`2`. Create a bar plot of average weight by site (`plot_id`)\n",
"with female and male values side by side for each site.\n",
"* Create a new DataFrame that contains only observations that are\n",
" of sex female or male and where weight values are greater than 0\n",
"* For the final plot, only select the\n",
Expand Down Expand Up @@ -345,7 +345,7 @@
"source": [
"# Calculate the mean weight for each plot_id and sex combination: \n",
"avg_by_site_sex = selection###\n",
"avg_by_site_sex.head()"
"avg_by_site_sex.tail()"
]
},
{
Expand Down Expand Up @@ -377,8 +377,8 @@
},
"outputs": [],
"source": [
"# And we can make a stacked bar plot from this:\n",
"table_site_sex.plot(kind='bar', stacked=True)"
"# And we can make a bar plot from this:\n",
"table_site_sex.plot(kind='bar')"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions en/04-combine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
},
"outputs": [],
"source": [
"taxa_site.plot(kind='bar', stacked=True)"
"taxa_site.plot(kind='bar', logy=True)"
]
},
{
Expand Down Expand Up @@ -548,7 +548,7 @@
},
"outputs": [],
"source": [
"pivot_taxa_sex_site.plot(kind=\"bar\", stacked=True)"
"pivot_taxa_sex_site.plot(kind=\"bar\")"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions en/05-altair.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
" 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",
"* In the `tooltip` channel, add `'sex'` at the beginning of the list\n",
"* Activate the `xOffset` channel and see what it does to the bar-plot\n",
"\n",
"(4 min.)"
]
Expand All @@ -516,7 +517,10 @@
" ###=['F', 'M'],\n",
" ###=['orange', 'green'],\n",
" ),\n",
" #xOffset='sex',\n",
" tooltip=[###, 'count()'],\n",
").properties(\n",
" width=480, # Fix the chart width (pixels)\n",
")"
]
},
Expand Down
10 changes: 5 additions & 5 deletions fr/02-selection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@
"lang": "fr"
},
"source": [
"`2`. Créez un graphique de barres empilées (ou *stacked bar-plot*)\n",
"montrant la moyenne des poids selon le site (`plot_id`),\n",
"mais avec les résultats des femelles et des mâles superposés.\n",
"`2`. Créez un graphique de barres montrant la moyenne\n",
"des poids selon le site (`plot_id`), mais avec les résultats\n",
"des femelles et des mâles côte à côte pour chaque site.\n",
"Pour la préparation initiale des données :\n",
"* Créez une sélection contenant seulement les enregistrements\n",
"ayant une valeur de `sex` (soit `F` ou `M`) et ayant un poids supérieur à 0\n",
Expand Down Expand Up @@ -380,8 +380,8 @@
},
"outputs": [],
"source": [
"# Créer le stacked bar plot\n",
"table_site_sexe.plot(kind='bar', stacked=True)"
"# Créer le bar plot\n",
"table_site_sexe.plot(kind='bar')"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions fr/04-combine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@
},
"outputs": [],
"source": [
"nb_par_site_taxa.plot(kind='bar', stacked=True)"
"nb_par_site_taxa.plot(kind='bar', logy=True)"
]
},
{
Expand Down Expand Up @@ -550,7 +550,7 @@
},
"outputs": [],
"source": [
"pivot_taxa_sex_site.plot(kind=\"bar\", stacked=True)"
"pivot_taxa_sex_site.plot(kind=\"bar\")"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions fr/05-altair.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@
" 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",
"* Dans le canal `tooltip`, ajoutez `'sex'` au début de la liste\n",
"* Expérimentez l'activation du canal `xOffset`\n",
"\n",
"(4 min.)"
]
Expand All @@ -514,7 +515,10 @@
" ###=['F', 'M'],\n",
" ###=['orange', 'green'],\n",
" ),\n",
" #xOffset='sex',\n",
" tooltip=[###, 'count()'],\n",
").properties(\n",
" width=480, # Fixer la largeur du graphique (pixels)\n",
")"
]
},
Expand Down
10 changes: 5 additions & 5 deletions solution-en/02-selection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@
"lang": "en"
},
"source": [
"`2`. Create a stacked bar plot of average weight by site\n",
"with male vs female values stacked for each site (`plot_id`).\n",
"`2`. Create a bar plot of average weight by site (`plot_id`)\n",
"with female and male values side by side for each site.\n",
"* Create a new DataFrame that contains only observations that are\n",
" of sex female or male and where weight values are greater than 0\n",
"* For the final plot, only select the\n",
Expand Down Expand Up @@ -345,7 +345,7 @@
"source": [
"# Calculate the mean weight for each plot_id and sex combination: \n",
"avg_by_site_sex = selection.groupby(['plot_id', 'sex']).mean()\n",
"avg_by_site_sex.head()"
"avg_by_site_sex.tail()"
]
},
{
Expand Down Expand Up @@ -377,8 +377,8 @@
},
"outputs": [],
"source": [
"# And we can make a stacked bar plot from this:\n",
"table_site_sex.plot(kind='bar', stacked=True)"
"# And we can make a bar plot from this:\n",
"table_site_sex.plot(kind='bar')"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions solution-en/04-combine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
},
"outputs": [],
"source": [
"taxa_site.plot(kind='bar', stacked=True)"
"taxa_site.plot(kind='bar', logy=True)"
]
},
{
Expand Down Expand Up @@ -548,7 +548,7 @@
},
"outputs": [],
"source": [
"pivot_taxa_sex_site.plot(kind=\"bar\", stacked=True)"
"pivot_taxa_sex_site.plot(kind=\"bar\")"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions solution-en/05-altair.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
" 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",
"* In the `tooltip` channel, add `'sex'` at the beginning of the list\n",
"* Activate the `xOffset` channel and see what it does to the bar-plot\n",
"\n",
"(4 min.)"
]
Expand All @@ -516,7 +517,10 @@
" domain=['F', 'M'],\n",
" range=['orange', 'green'],\n",
" ),\n",
" xOffset='sex',\n",
" tooltip=['sex', 'count()'],\n",
").properties(\n",
" width=480, # Fix the chart width (pixels)\n",
")"
]
},
Expand Down
10 changes: 5 additions & 5 deletions solution-fr/02-selection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@
"lang": "fr"
},
"source": [
"`2`. Créez un graphique de barres empilées (ou *stacked bar-plot*)\n",
"montrant la moyenne des poids selon le site (`plot_id`),\n",
"mais avec les résultats des femelles et des mâles superposés.\n",
"`2`. Créez un graphique de barres montrant la moyenne\n",
"des poids selon le site (`plot_id`), mais avec les résultats\n",
"des femelles et des mâles côte à côte pour chaque site.\n",
"Pour la préparation initiale des données :\n",
"* Créez une sélection contenant seulement les enregistrements\n",
"ayant une valeur de `sex` (soit `F` ou `M`) et ayant un poids supérieur à 0\n",
Expand Down Expand Up @@ -380,8 +380,8 @@
},
"outputs": [],
"source": [
"# Créer le stacked bar plot\n",
"table_site_sexe.plot(kind='bar', stacked=True)"
"# Créer le bar plot\n",
"table_site_sexe.plot(kind='bar')"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions solution-fr/04-combine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@
},
"outputs": [],
"source": [
"nb_par_site_taxa.plot(kind='bar', stacked=True)"
"nb_par_site_taxa.plot(kind='bar', logy=True)"
]
},
{
Expand Down Expand Up @@ -550,7 +550,7 @@
},
"outputs": [],
"source": [
"pivot_taxa_sex_site.plot(kind=\"bar\", stacked=True)"
"pivot_taxa_sex_site.plot(kind=\"bar\")"
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions solution-fr/05-altair.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@
" 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",
"* Dans le canal `tooltip`, ajoutez `'sex'` au début de la liste\n",
"* Expérimentez l'activation du canal `xOffset`\n",
"\n",
"(4 min.)"
]
Expand All @@ -514,7 +515,10 @@
" domain=['F', 'M'],\n",
" range=['orange', 'green'],\n",
" ),\n",
" xOffset='sex',\n",
" tooltip=['sex', 'count()'],\n",
").properties(\n",
" width=480, # Fixer la largeur du graphique (pixels)\n",
")"
]
},
Expand Down
22 changes: 11 additions & 11 deletions src/02-selection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,9 @@
"lang": "fr"
},
"source": [
"`2`. Créez un graphique de barres empilées (ou *stacked bar-plot*)\n",
"montrant la moyenne des poids selon le site (`plot_id`),\n",
"mais avec les résultats des femelles et des mâles superposés.\n",
"`2`. Créez un graphique de barres montrant la moyenne\n",
"des poids selon le site (`plot_id`), mais avec les résultats\n",
"des femelles et des mâles côte à côte pour chaque site.\n",
"Pour la préparation initiale des données :\n",
"* Créez une sélection contenant seulement les enregistrements\n",
"ayant une valeur de `sex` (soit `F` ou `M`) et ayant un poids supérieur à 0\n",
Expand All @@ -789,8 +789,8 @@
"lang": "en"
},
"source": [
"`2`. Create a stacked bar plot of average weight by site\n",
"with male vs female values stacked for each site (`plot_id`).\n",
"`2`. Create a bar plot of average weight by site (`plot_id`)\n",
"with female and male values side by side for each site.\n",
"* Create a new DataFrame that contains only observations that are\n",
" of sex female or male and where weight values are greater than 0\n",
"* For the final plot, only select the\n",
Expand Down Expand Up @@ -931,7 +931,7 @@
"source": [
"# Calculate the mean weight for each plot_id and sex combination: \n",
"avg_by_site_sex = selection.groupby(['plot_id', 'sex']).mean()\n",
"avg_by_site_sex.head()"
"avg_by_site_sex.tail()"
]
},
{
Expand All @@ -948,7 +948,7 @@
"source": [
"# Calculate the mean weight for each plot_id and sex combination: \n",
"avg_by_site_sex = selection###\n",
"avg_by_site_sex.head()"
"avg_by_site_sex.tail()"
]
},
{
Expand Down Expand Up @@ -1040,8 +1040,8 @@
},
"outputs": [],
"source": [
"# Créer le stacked bar plot\n",
"table_site_sexe.plot(kind='bar', stacked=True)"
"# Créer le bar plot\n",
"table_site_sexe.plot(kind='bar')"
]
},
{
Expand All @@ -1053,8 +1053,8 @@
},
"outputs": [],
"source": [
"# And we can make a stacked bar plot from this:\n",
"table_site_sex.plot(kind='bar', stacked=True)"
"# And we can make a bar plot from this:\n",
"table_site_sex.plot(kind='bar')"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/04-combine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@
},
"outputs": [],
"source": [
"nb_par_site_taxa.plot(kind='bar', stacked=True)"
"nb_par_site_taxa.plot(kind='bar', logy=True)"
]
},
{
Expand All @@ -1128,7 +1128,7 @@
},
"outputs": [],
"source": [
"taxa_site.plot(kind='bar', stacked=True)"
"taxa_site.plot(kind='bar', logy=True)"
]
},
{
Expand Down Expand Up @@ -1291,7 +1291,7 @@
},
"outputs": [],
"source": [
"pivot_taxa_sex_site.plot(kind=\"bar\", stacked=True)"
"pivot_taxa_sex_site.plot(kind=\"bar\")"
]
},
{
Expand Down
Loading

0 comments on commit 9f599b1

Please sign in to comment.