2025.44 changes
@@ -542,52 +542,280 @@ aux éléments du dessin.
|
||||
```python {.numberLines}
|
||||
import pandas as pd
|
||||
from plotly import express as px
|
||||
from plotly.colors import qualitative
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["pomme", "poire", "banane", "pêche"],
|
||||
"price": [1.99, 2.49, 2.99, 3.49], "wpu": [200, 180, 140, 200]
|
||||
"name": ["headphones", "microphone", "speaker", "powerbank", "tablet", "laptop"],
|
||||
"price": [99.99, 49.99, 149.99, 29.99, 199.99, 499.99],
|
||||
"merchant": ["amazon", "amazon", "bestbuy", "amazon", "newegg", "amazon"],
|
||||
"color": ["black", "silver", "white", "red", "gray", "silver"]
|
||||
})
|
||||
figure = px.pie(data, values="price", names="product", title="Prix", color_discrete_sequence=["red", "orange", "yellow", "#8F0"])
|
||||
figure.layout.update({"template": "seaborn", "title": "Prix au kilo", "font": {"family": "Cabin", "size": 13}})
|
||||
figure.show()
|
||||
figure = px.pie(data, values="price", names="name", title="Prix", texttemplate="", color_discrete_sequence=qualitative.Bold)
|
||||
figure.layout.update({"template": "seaborn", "title": "Prix à l'unité", "font": {"family": "Cabin", "size": 13}})
|
||||
figure.show(renderer="browser")
|
||||
```
|
||||
|
||||
Plotly Express fournit des séquences ou dégradés de couleurs, dont la référence est disponible ci-dessous :
|
||||
----
|
||||
|
||||
[Couleurs et séquences de couleurs](https://plotly.com/python/discrete-color/)
|
||||

|
||||
|
||||
----
|
||||
|
||||

|
||||
### Gradients de couleurs
|
||||
|
||||
----
|
||||
|
||||
### Couleur dépendante de la valeur
|
||||
|
||||
Vous pouvez sur certains graphiques définir un gradient à appliquer aux éléments du dessin
|
||||
selon une valeur qui leur est associée. Ici, nous avons un graphique en barres, où la couleur
|
||||
de chaque barre dépend de la valeur de la colonne `price`.
|
||||
Vous pouvez appliquer des couleurs prédéfinies ou continues à vos graphiques. Vous pouvez utiliser une palette
|
||||
servant de dégradé pour colorier les éléments du dessin selon une valeur associée.
|
||||
|
||||
```python {.numberLines}
|
||||
import pandas as pd
|
||||
from plotly import express as px
|
||||
from plotly.colors import sequential, qualitative
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["pomme", "poire", "banane", "pêche"],
|
||||
"price": [1.99, 2.49, 2.99, 3.49], "wpu": [200, 180, 140, 200]
|
||||
|
||||
df = pd.DataFrame(data={
|
||||
"month": [f"2005-{i:02d}" for i in range(1, 13)],
|
||||
"temperature": [4.4, 6.8, 9.2, 11.5, 13.8, 16.3, 19.1, 21.4, 22.9, 20.5, 17.2, 13.9]
|
||||
})
|
||||
figure = px.bar(data, y="price", x="product", title="Prix", color="price", color_continuous_scale=["red", "orange", "yellow", "#8F0"])
|
||||
figure.layout.update({"template": "seaborn", "title": "Prix au kilo", "font": {"family": "Cabin", "size": 13}})
|
||||
figure.show()
|
||||
plot = px.bar(
|
||||
df, x="month", y="temperature", color="temperature", template="seaborn",
|
||||
title="Temperatures mensuelles de 2005",
|
||||
color_continuous_scale=sequential.Turbo,
|
||||
labels={"month": "Mois", "temperature": "Température (°C)"}
|
||||
)
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
|
||||
plot.show()
|
||||
```
|
||||
|
||||
Ici, l'argument `color` permet d'indiquer sur les valeurs de quelle colonne colorier les barres.
|
||||
L'argument `color_continuous_scale` permet de définir les couleurs d'un dégradé à utiliser pour
|
||||
colorier les barres.
|
||||
|
||||
----
|
||||
|
||||

|
||||

|
||||
|
||||
----
|
||||
|
||||
### Palettes de couleurs personnalisées
|
||||
|
||||
Les palettes utilisées dans les exemples précédents sont simplement des listes de couleurs prédéfinies
|
||||
par Plotly, mais vous pouvez définir vos propres palettes de couleurs via des listes composées de couleurs sous plusieurs formats :
|
||||
|
||||
| Format de couleur | Exemple(s) | Description / notes |
|
||||
| ------------------------ | -------------------------------- | ------------------------------------------------ |
|
||||
| Nom de couleur CSS | `"red"`, `"blue"`, `"green"` | Noms de couleurs standards en CSS |
|
||||
| Code hexadécimal | `"#FF5733"`, `"#33FF57"` | Codes hexadécimaux RGB |
|
||||
| Code RGB | `"rgb(255,0,0)"`, `"rgb(0,255,0)"` | Codes RGB avec valeurs décimales (0-255) |
|
||||
| Code RGBA | `"rgba(255,0,0,0.5)"` | Codes RGBA avec valeurs décimales (0-255) et alpha (0-1) |
|
||||
|
||||
----
|
||||
|
||||
Ici on définit manuellement une suite de couleurs à utiliser pour colorier les barres, allant du rouge au jaune.
|
||||
|
||||
```python {.numberLines}
|
||||
import pandas as pd
|
||||
from plotly import express as px
|
||||
from plotly.colors import sequential, qualitative
|
||||
|
||||
|
||||
df = pd.DataFrame(data={
|
||||
"month": [f"2005-{i:02d}" for i in range(1, 13)],
|
||||
"temperature": [4.4, 6.8, 9.2, 11.5, 13.8, 16.3, 19.1, 21.4, 22.9, 20.5, 17.2, 13.9]
|
||||
})
|
||||
plot = px.bar(
|
||||
df, x="month", y="temperature", color="temperature", template="seaborn",
|
||||
title="Temperatures mensuelles de 2005",
|
||||
color_continuous_scale=["#FF0020", "rgb(255,165,0)", "rgba(255,255,0,0.8)"],
|
||||
labels={"month": "Mois", "temperature": "Température (°C)"}
|
||||
)
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
|
||||
plot.show()
|
||||
```
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
[Couleurs et séquences de couleurs](https://plotly.com/python/discrete-color/)
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
[Couleurs et séquences de couleurs](https://plotly.com/python/discrete-color/)
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
[Couleurs continues](https://plotly.com/python/builtin-colorscales/#builtin-sequential-color-scales)
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
### Sous-graphiques ([subplots]{.naming})
|
||||
|
||||
Plotly propose un module `plotly.subplots` permettant de créer des figures composées de plusieurs sous-graphiques.
|
||||
Vous pouvez définir la mise en page de vos sous-graphiques, en précisant le nombre de lignes et de colonnes, ainsi que
|
||||
la taille de chaque sous-graphe.
|
||||
|
||||
```python {.numberLines}
|
||||
import pandas as pd
|
||||
from plotly.subplots import make_subplots
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600]
|
||||
})
|
||||
figure: Figure = make_subplots(rows=1, cols=2, subplot_titles=("Prix", "Poids unitaires"))
|
||||
figure.add_trace(Bar(name="Prix", x=data["product"], y=data["price"]), row=1, col=1)
|
||||
figure.add_trace(Bar(name="Poids", x=data["product"], y=data["weight"]), row=1, col=2)
|
||||
figure.update_layout(template="seaborn", title="Prix et poids unitaires", font={"family": "Cabin", "size": 13})
|
||||
figure.show(renderer="browser")
|
||||
```
|
||||
|
||||
Vous pouvez également créer un objet `Figure`{.python} normalement, et exécuter la méthode `figure.set_subplots`{.python}
|
||||
pour obtenir le même objet.
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
#### Propriétés des colonnes et lignes
|
||||
|
||||
Vous pouvez définir les dimensions relatives des colonnes et lignes lors de la création de sous-graphiques.
|
||||
|
||||
```python {.numberLines}
|
||||
import pandas as pd
|
||||
from plotly.subplots import make_subplots
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600]
|
||||
})
|
||||
figure: Figure = make_subplots(rows=1, cols=2, column_widths=[0.6, 0.4], row_heights=[1.0])
|
||||
figure.add_trace(Bar(name="Prix", x=data["product"], y=data["price"]), row=1, col=1)
|
||||
figure.add_trace(Bar(name="Poids", x=data["product"], y=data["weight"]), row=1, col=2)
|
||||
figure.update_layout(template="seaborn", title="Prix et poids unitaires", font={"family": "Cabin", "size": 13})
|
||||
figure.show(renderer="browser")
|
||||
```
|
||||
|
||||
Ici les colonnes 1 et 2 représentent respectivement 60% et 40% de la largeur totale.
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
### Éléments graphiques
|
||||
|
||||
Vous pouvez agrémenter manuellement vos graphiques d'éléments visuels; les objets `Figure`{.python}
|
||||
possèdent de nombreuses méthodes pour ajouter des éléments visuels (_images_, _rectangles_, autres…)
|
||||
|
||||
----
|
||||
|
||||
#### Ajouter une image
|
||||
|
||||
```python {.numberLines}
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
from PIL import Image
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600]
|
||||
})
|
||||
figure: Figure = Figure(data=[Bar(name="Prix", x=data["product"], y=data["price"])])
|
||||
figure.add_layout_image(
|
||||
layer="above",
|
||||
x=0,
|
||||
y=1.02,
|
||||
xref="paper",
|
||||
yref="paper",
|
||||
sizex=1,
|
||||
sizey=0.075,
|
||||
xanchor="left",
|
||||
yanchor="bottom",
|
||||
source=Image.open("images/python-logo-square.png")
|
||||
)
|
||||
figure.update_layout(template="seaborn", title="Prix et poids unitaires", font={"family": "Cabin", "size": 13})
|
||||
figure.show(renderer="browser")
|
||||
```
|
||||
|
||||
**Note** : Nécessite une image valide.
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
#### Options de taille, d'échelle et d'alignement
|
||||
|
||||
| Argument | Type / valeur possible | Description / notes |
|
||||
|-----------|----------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `xref` | `"paper"` / `"pixel"` / `"x"` | Référence horizontale de l'image. Lorsque `xref` vaut `"paper"`, `x` est relative à la largeur totale du graphique. Lorsque `xref` vaut `"pixel"`, `x` est en pixels. |
|
||||
| `yref` | `"paper"` / `"pixel"` / `"y"` | Référence verticale de l'image. Lorsque `yref` vaut `"paper"`, `y` est relative à la hauteur totale du graphique. Lorsque `yref` vaut `"pixel"`, `y` est en pixels. |
|
||||
| `xanchor` | `"auto"` / `"left"` / `"center"` / `"right"` | Alignement horizontal de l'image selon `x`. |
|
||||
| `yanchor` | `"auto"` / `"top"` / `"middle"` / `"bottom"` | Alignement vertical de l'image selon `y`. |
|
||||
| `x` | nombre | Position horizontale de l'image (relative à `xref`). |
|
||||
| `y` | nombre | Position verticale de l'image (relative à `yref`). |
|
||||
| `sizex` | nombre ∈ [0, 1] | Largeur relative de l'image selon l'axe des X. |
|
||||
| `sizey` | nombre ∈ [0, 1] | Hauteur relative de l'image selon l'axe des Y. |
|
||||
| `layer` | `"above"` / `"below"` / `"between"` | Couche de l'image par rapport aux autres éléments du graphique. |
|
||||
| `source` | `PIL.Image` | Image à afficher. |
|
||||
|
||||
----
|
||||
|
||||
#### Ajouter un rectangle horizontal
|
||||
|
||||
```python {.numberLines}
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar, Scatter
|
||||
|
||||
data = pd.DataFrame(
|
||||
data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600],
|
||||
}
|
||||
)
|
||||
figure: Figure = Figure(data=[Bar(name="Prix", x=data["product"], y=data["price"])])
|
||||
figure.add_hrect(y0=2.75, y1=4.5, fillcolor="gray", opacity=0.25, layer="below")
|
||||
figure.update_layout(
|
||||
template="seaborn",
|
||||
title="Prix et poids unitaires",
|
||||
font={"family": "Cabin", "size": 13},
|
||||
xaxis={"title": "Produit", "showgrid": False},
|
||||
yaxis={"title": "Prix (€)", "showgrid": False}
|
||||
)
|
||||
figure.show(renderer="browser")
|
||||
```
|
||||
|
||||
----
|
||||
|
||||

|
||||
|
||||
----
|
||||
|
||||
#### Options de rectangle
|
||||
|
||||
| Argument | Type / valeur possible | Description / notes |
|
||||
|-------------|-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `y0` | nombre | Position verticale de la ligne en bas (relative à `yref`). |
|
||||
| `y1` | nombre | Position verticale de la ligne en haut (relative à `yref`). |
|
||||
| `yref` | `"paper"` / `"pixel"` / `"y"` | Référence verticale de la ligne. Lorsque `yref` vaut `"paper"`, `y` est relative à la hauteur totale du graphique. Lorsque `yref` vaut `"pixel"`, `y` est en pixels. |
|
||||
| `fillcolor` | `str` (couleur HTML) | Couleur de remplissage de la ligne. |
|
||||
| `line` | `dict` | Dictionnaire des propriétés de la ligne (voir la documentation de Plotly). |
|
||||
| `opacity` | `float` ∈ [0, 1] | Opacité de la ligne. |
|
||||
| `layer` | `"above"` / `"below"` / `"between"` | Couche de la ligne par rapport aux autres éléments du graphique. |
|
||||
|
||||
----
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 1009 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 922 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 72 KiB |
BIN
documentation/assets/images/eda-plotly-subplot-base.png
Normal file
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 90 KiB |
BIN
documentation/assets/images/eda-plotly-trace-hrect.png
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
documentation/assets/images/eda-plotly-trace-image.png
Normal file
|
After Width: | Height: | Size: 64 KiB |
1
source/plotting/charts/eda-plotly-colors-continuous.svg
Normal file
|
After Width: | Height: | Size: 1009 KiB |
1
source/plotting/charts/eda-plotly-colors-qualitative.svg
Normal file
|
After Width: | Height: | Size: 58 KiB |
1
source/plotting/charts/eda-plotly-colors-sequential.svg
Normal file
|
After Width: | Height: | Size: 922 KiB |
BIN
source/plotting/charts/images/astral-python.png
Normal file
|
After Width: | Height: | Size: 1018 B |
BIN
source/plotting/charts/images/python-logo-square.png
Normal file
|
After Width: | Height: | Size: 88 KiB |
BIN
source/plotting/charts/images/svelte.webp
Normal file
|
After Width: | Height: | Size: 12 KiB |
17
source/plotting/charts/plotly_bar_colors.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import pandas as pd
|
||||
from plotly import express as px
|
||||
from plotly.colors import sequential, qualitative
|
||||
|
||||
|
||||
df = pd.DataFrame(data={
|
||||
"month": [f"2005-{i:02d}" for i in range(1, 13)],
|
||||
"temperature": [4.4, 6.8, 9.2, 11.5, 13.8, 16.3, 19.1, 21.4, 22.9, 20.5, 17.2, 13.9]
|
||||
})
|
||||
plot = px.bar(
|
||||
df, x="month", y="temperature", color="temperature", template="seaborn",
|
||||
title="Temperatures mensuelles de 2005",
|
||||
color_continuous_scale=sequential.Turbo,
|
||||
labels={"month": "Mois", "temperature": "Température (°C)"}
|
||||
)
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
|
||||
plot.show()
|
||||
17
source/plotting/charts/plotly_bar_colors_custom.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import pandas as pd
|
||||
from plotly import express as px
|
||||
from plotly.colors import sequential, qualitative
|
||||
|
||||
|
||||
df = pd.DataFrame(data={
|
||||
"month": [f"2005-{i:02d}" for i in range(1, 13)],
|
||||
"temperature": [4.4, 6.8, 9.2, 11.5, 13.8, 16.3, 19.1, 21.4, 22.9, 20.5, 17.2, 13.9]
|
||||
})
|
||||
plot = px.bar(
|
||||
df, x="month", y="temperature", color="temperature", template="seaborn",
|
||||
title="Temperatures mensuelles de 2005",
|
||||
color_continuous_scale=["#FF0020", "rgb(255,165,0)", "rgba(255,255,0,0.8)"],
|
||||
labels={"month": "Mois", "temperature": "Température (°C)"}
|
||||
)
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
|
||||
plot.show()
|
||||
14
source/plotting/charts/plotly_pie_colors.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pandas as pd
|
||||
from plotly import express as px
|
||||
from plotly.colors import qualitative
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"name": ["headphones", "microphone", "speaker", "powerbank", "tablet", "laptop"],
|
||||
"price": [99.99, 49.99, 149.99, 29.99, 199.99, 279.99],
|
||||
"merchant": ["amazon", "amazon", "bestbuy", "amazon", "newegg", "amazon"],
|
||||
"color": ["black", "silver", "white", "red", "gray", "silver"]
|
||||
})
|
||||
figure = px.pie(data, values="price", names="name", title="Prix", color_discrete_sequence=qualitative.Bold)
|
||||
figure.layout.update({"template": "seaborn", "title": "Prix à l'unité", "font": {"family": "Cabin", "size": 13}, "width": 1080, "height": 720})
|
||||
figure.update_traces(textposition="inside", textinfo="percent+label", texttemplate="%{label}<br>%{value}€ (%{percent:.2%})")
|
||||
figure.show()
|
||||
19
source/plotting/charts/plotly_subplot_base.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import pandas as pd
|
||||
from plotly._subplots import SubplotXY
|
||||
from plotly.subplots import make_subplots
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600]
|
||||
})
|
||||
figure: Figure = make_subplots(rows=1, cols=3, subplot_titles=("Prix", "Poids unitaires"))
|
||||
subplot = figure.get_subplot(row=1, col=2)
|
||||
subplot.xaxis["domain"] = [0.3555555, 1.0]
|
||||
print(subplot, dir(subplot))
|
||||
figure.add_trace(Bar(name="Prix", x=data["product"], y=data["price"]), row=1, col=1)
|
||||
figure.add_trace(Bar(name="Poids", x=data["product"], y=data["weight"]), row=1, col=2)
|
||||
figure.update_layout(template="seaborn", title="Prix et poids unitaires", font={"family": "Cabin", "size": 13})
|
||||
figure.update_traces(row=1, col=2, specs=2)
|
||||
figure.show(renderer="browser")
|
||||
14
source/plotting/charts/plotly_subplot_widths.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pandas as pd
|
||||
from plotly.subplots import make_subplots
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600]
|
||||
})
|
||||
figure: Figure = make_subplots(rows=1, cols=2, column_widths=[0.6, 0.4], row_heights=[1.0])
|
||||
figure.add_trace(Bar(name="Prix", x=data["product"], y=data["price"]), row=1, col=1)
|
||||
figure.add_trace(Bar(name="Poids", x=data["product"], y=data["weight"]), row=1, col=2)
|
||||
figure.update_layout(template="seaborn", title="Prix et poids unitaires", font={"family": "Cabin", "size": 13})
|
||||
figure.show()
|
||||
55
source/plotting/charts/plotly_swatches.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import plotly.express as px
|
||||
from plotly.graph_objects import Figure, Scatter
|
||||
|
||||
COLS: int = 3
|
||||
fig: Figure = px.colors.sequential.swatches_continuous()
|
||||
fig3: Figure = px.colors.qualitative.swatches()
|
||||
figb: Figure = px.colors.sequential.swatches()
|
||||
|
||||
fig2 = Figure(layout={
|
||||
"title": "Palette de couleurs continues Plotly Sequential",
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"xaxis": {"visible": False, "showticklabels": False},
|
||||
"yaxis": {"visible": False, "showticklabels": False},
|
||||
"legend": {"visible": False},
|
||||
"width": 1400,
|
||||
}).set_subplots(rows=22, cols=COLS)
|
||||
for i, p in enumerate(fig.select_traces()): #type: int, Scatter
|
||||
fig2.add_trace(p, row= (i // COLS) + 1, col=(i % COLS) + 1)
|
||||
fig2.update_xaxes({"visible": False, "showticklabels": False, "showgrid": False})
|
||||
fig2.update_yaxes({"visible": True, "showticklabels": True, "showgrid": False})
|
||||
fig2.update_yaxes(tickfont={"size": 11}, ticksuffix=" ")
|
||||
fig2.write_image("eda-plotly-colors-continuous.svg")
|
||||
# fig2.show(renderer="browser")
|
||||
|
||||
fig4 = Figure(layout={
|
||||
"title": "Palette de couleurs séquentielles Plotly Sequential",
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"xaxis": {"visible": False, "showticklabels": False},
|
||||
"yaxis": {"visible": False, "showticklabels": False},
|
||||
"legend": {"visible": False},
|
||||
"width": 1400,
|
||||
"margin": {"t": 100, "b": 50, "l": 60, "r": 50},
|
||||
}).set_subplots(rows=22, cols=COLS)
|
||||
for i, p in enumerate(figb.select_traces()): #type: int, Scatter
|
||||
fig4.add_trace(p, row= (i // COLS) + 1, col=(i % COLS) + 1)
|
||||
fig4.update_xaxes({"visible": False, "showticklabels": False, "showgrid": False})
|
||||
fig4.update_yaxes({"visible": True, "showticklabels": True, "showgrid": False})
|
||||
fig4.update_yaxes(tickfont={"size": 11}, ticksuffix=" ")
|
||||
fig4.write_image("eda-plotly-colors-sequential.svg")
|
||||
|
||||
fig3.update_layout({
|
||||
"title": "Palette de couleurs qualitatives Plotly Qualitative",
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"xaxis": {"visible": False, "showticklabels": False},
|
||||
"yaxis": {"visible": False, "showticklabels": False},
|
||||
"legend": {"visible": False},
|
||||
"width": 1200,
|
||||
"margin": {"t": 100, "b": 50, "l": 60, "r": 50},
|
||||
})
|
||||
fig3.update_xaxes({"visible": False, "showticklabels": False, "showgrid": False})
|
||||
fig3.update_yaxes({"visible": True, "showticklabels": True, "showgrid": False})
|
||||
fig3.update_yaxes(tickfont={"size": 11}, ticksuffix=" ")
|
||||
fig3.write_image("eda-plotly-colors-qualitative.svg")
|
||||
|
||||
|
||||
30
source/plotting/charts/plotly_trace_image.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
from PIL import Image
|
||||
|
||||
data = pd.DataFrame(
|
||||
data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600],
|
||||
}
|
||||
)
|
||||
figure: Figure = Figure(data=[Bar(name="Prix", x=data["product"], y=data["price"])])
|
||||
figure.add_layout_image(
|
||||
layer="above",
|
||||
x=0,
|
||||
y=1.02,
|
||||
xref="paper",
|
||||
yref="paper",
|
||||
sizex=1,
|
||||
sizey=0.075,
|
||||
xanchor="left",
|
||||
yanchor="bottom",
|
||||
source=Image.open("images/python-logo-square.png"),
|
||||
)
|
||||
figure.update_layout(
|
||||
template="seaborn",
|
||||
title="Prix et poids unitaires",
|
||||
font={"family": "Cabin", "size": 13},
|
||||
)
|
||||
figure.show(renderer="browser")
|
||||
20
source/plotting/charts/plotly_trace_rectangle.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar, Scatter
|
||||
|
||||
data = pd.DataFrame(
|
||||
data={
|
||||
"product": ["tarte", "gâteau", "biscuit", "mille-feuille", "éclair", "brownie"],
|
||||
"price": [2.99, 3.49, 1.99, 4.99, 5.99, 6.99],
|
||||
"weight": [250, 300, 200, 400, 500, 600],
|
||||
}
|
||||
)
|
||||
figure: Figure = Figure(data=[Bar(name="Prix", x=data["product"], y=data["price"])])
|
||||
figure.add_hrect(y0=2.75, y1=4.5, fillcolor="gray", opacity=0.25, layer="below")
|
||||
figure.update_layout(
|
||||
template="seaborn",
|
||||
title="Prix et poids unitaires",
|
||||
font={"family": "Cabin", "size": 13},
|
||||
xaxis={"title": "Produit", "showgrid": False},
|
||||
yaxis={"title": "Prix (€)", "showgrid": False}
|
||||
)
|
||||
figure.show(renderer="browser")
|
||||