Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| python:matplotlib [2023/06/27 10:29] – [Types de graphiques] do not force square heatmaps phsw | python:matplotlib [2024/10/06 15:47] (Version actuelle) – [Matplotlib] add link phsw | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| * [[https:// | * [[https:// | ||
| + | * [[https:// | ||
| + | * https:// | ||
| + | |||
| Ligne 80: | Ligne 83: | ||
| </ | </ | ||
| - | Paramètres facultatifs de '' | + | Paramètres facultatifs de '' |
| - | * '' | + | * '' |
| - | * '' | + | * '' |
| - | * '' | + | * '' |
| - | * '' | + | * '' |
| - | * '' | + | * '' |
| - | * '' | + | * '' |
| - | * '' | + | * '' |
| + | * '' | ||
| La taille de la police de la légende peut être définie par défaut: | La taille de la police de la légende peut être définie par défaut: | ||
| Ligne 286: | Ligne 290: | ||
| # or: | # or: | ||
| plt.xticks([]) | plt.xticks([]) | ||
| + | </ | ||
| + | |||
| + | Changer l' | ||
| + | <code python> | ||
| + | plt.yticks(ticks, | ||
| + | # ou | ||
| + | ax.set_yticks(ticks, | ||
| </ | </ | ||
| Ligne 307: | Ligne 318: | ||
| for tick in ax.get_xticklabels(): | for tick in ax.get_xticklabels(): | ||
| tick.set_rotation(45) | tick.set_rotation(45) | ||
| + | | ||
| + | # or (with Matplotlib >= 3.5): | ||
| + | ax.set_xticks(ax.get_xticks(), | ||
| # Pad margins so that markers don't get clipped by the axes | # Pad margins so that markers don't get clipped by the axes | ||
| Ligne 442: | Ligne 456: | ||
| for i in range(len(bars)): | for i in range(len(bars)): | ||
| bars[i].set_hatch(hatches[i]) | bars[i].set_hatch(hatches[i]) | ||
| + | # pour avoir un export correct dans les PDFs, utiliser plutôt : | ||
| + | bars[i].set(hatch="//", | ||
| </ | </ | ||
| Ligne 516: | Ligne 532: | ||
| <code python> | <code python> | ||
| fig.suptitle(title) | fig.suptitle(title) | ||
| + | </ | ||
| + | |||
| + | Il est possible de préciser à quelle hauteur placer le titre ([[https:// | ||
| + | <code python> | ||
| + | fig.suptitle(title, | ||
| </ | </ | ||
| Ligne 541: | Ligne 562: | ||
| Pour agrandir la heatmap, il peut être aussi utile de ne pas utiliser '' | Pour agrandir la heatmap, il peut être aussi utile de ne pas utiliser '' | ||
| + | |||
| + | Ajouter du texte dans chaque case de la heatmap ([[https:// | ||
| + | <code python> | ||
| + | for i in range(len(vegetables)): | ||
| + | for j in range(len(farmers)): | ||
| + | text = ax.text(j, i, harvest[i, j], ha=" | ||
| + | </ | ||
| Ligne 553: | Ligne 581: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | === Boxplots === | ||
| + | |||
| + | Pour que Matplotlib calcule directement les statistiques : '' | ||
| + | |||
| + | Pour fournir nous-mêmes les statistiques à Matplotlib : '' | ||
| + | |||
| + | |||
| + | == Changer la couleur de fond == | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | <code python> | ||
| + | boxplot = ax1.boxplot(all_data, | ||
| + | for b in boxplot[' | ||
| + | b.set_facecolor(color) | ||
| + | </ | ||
| + | |||
| + | == Légende correspondante == | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | <code python> | ||
| + | boxplot = ax.boxplot(all_data, | ||
| + | ax.legend([boxplot[" | ||
| + | </ | ||
| Ligne 605: | Ligne 660: | ||
| from matplotlib.patches import Patch | from matplotlib.patches import Patch | ||
| - | Patch(hatch=" | + | Patch(hatch=" |
| </ | </ | ||
| Ligne 692: | Ligne 747: | ||
| </ | </ | ||
| + | |||
| + | |||
| + | === Définir le centre de la colorbar === | ||
| + | |||
| + | Pour les palettes des couleurs divergentes ([[https:// | ||
| + | <code python> | ||
| + | from matplotlib.colors import TwoSlopeNorm | ||
| + | |||
| + | divnorm = TwoSlopeNorm(vmin=0, | ||
| + | im = ax.imshow(matrix, | ||
| + | </ | ||