2025.42 changes
This commit is contained in:
@@ -2,7 +2,7 @@ import pandas as pd
|
||||
from matplotlib import use, pyplot
|
||||
|
||||
# Utiliser tkinter
|
||||
use("TkAgg")
|
||||
# use("TkAgg")
|
||||
pyplot.style.use('ggplot')
|
||||
pyplot.rcParams["font.family"] = "Cabin"
|
||||
|
||||
|
||||
14
source/plotting/charts/plotly_figure_bar.py
Normal file
14
source/plotting/charts/plotly_figure_bar.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
df = pd.DataFrame(data={"label": ["Citron", "Pomme", "Mangue"], "price": [1.99, 3.97, 6.8]})
|
||||
figure = Figure(
|
||||
data=[Bar(x=df["label"], y=df["price"])],
|
||||
layout={
|
||||
"font": {"family": "Cabin", "size": 20},
|
||||
"title": "Prix au kilo",
|
||||
}
|
||||
)
|
||||
figure.show(renderer="browser")
|
||||
20
source/plotting/charts/plotly_figure_multiaxis.py
Normal file
20
source/plotting/charts/plotly_figure_multiaxis.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Bar
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["pomme", "poire", "banane", "pêche"],
|
||||
"price": [1.99, 2.49, 2.99, 3.49], "wpu": [200, 180, 140, 200]
|
||||
})
|
||||
figure = Figure([
|
||||
Bar(name="Prix", x=data["product"], y=data["price"], yaxis="y1", offsetgroup=1, texttemplate="%{y:.2f}€"),
|
||||
Bar(name="Poids", x=data["product"], y=data["wpu"], yaxis="y2", offsetgroup=2, texttemplate="%{y:.2f}g"),
|
||||
])
|
||||
# Afficher le dernier graphique généré
|
||||
figure.layout.update({
|
||||
"template": "seaborn",
|
||||
"title": "Prix et poids unitaires",
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"yaxis1": {"title": "Prix (€)", "color": "red"},
|
||||
"yaxis2": {"title": "Poids (g)", "overlaying": "y1", "side": "right"}
|
||||
})
|
||||
figure.show(renderer="browser")
|
||||
27
source/plotting/charts/plotly_figure_pie.py
Normal file
27
source/plotting/charts/plotly_figure_pie.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Pie
|
||||
from plotly.colors import qualitative
|
||||
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["oignon", "carotte", "pomme", "poire", "radis", "tomate"],
|
||||
"category": ["légume", "légume", "fruit", "fruit", "légume", "fruit"],
|
||||
"origin": ["Espagne", "France", "France", "France", "France", "Espagne"],
|
||||
"price": [1.69, 2.49, 2.99, 1.79, 1.29, 2.99]
|
||||
})
|
||||
figure = Figure(
|
||||
data=[Pie(
|
||||
values=data["price"],
|
||||
labels=data["product"].str.title(),
|
||||
customdata=data[["category", "origin"]],
|
||||
title="Prix",
|
||||
textinfo="label+value",
|
||||
texttemplate="<b>%{label}</b><br>%{value:.2f}€<br><em>%{customdata[0]}</em><br>%{customdata[1]}",
|
||||
insidetextorientation="tangential")
|
||||
],
|
||||
layout={
|
||||
"template": "seaborn",
|
||||
"font": {"family": "Cabin", "size": 20},
|
||||
"title": "Prix au kilo",
|
||||
"piecolorway": qualitative.Prism
|
||||
})
|
||||
figure.show(renderer="browser")
|
||||
29
source/plotting/charts/plotly_figure_sunburst.py
Normal file
29
source/plotting/charts/plotly_figure_sunburst.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import pandas as pd
|
||||
from plotly.graph_objs import Figure, Sunburst
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
df = pd.DataFrame(data={
|
||||
"continent": ["Europe", "Europe", "Europe", "Europe", "Europe", "Europe", "Europe", "Asia", "Asia"],
|
||||
"country": ["France", "France", "Spain", "Spain", "England", "England", "England", "China", "China"],
|
||||
"city": ["Montpellier", "Bordeaux", "Madrid", "Valencia", "London", "Manchester", "Bristol", "Beijing", "Shanghai"],
|
||||
"sales": [150_000, 127_000, 97_200, 137_250, 200_000, 180_000, 150_000, 120_000, 140_000]
|
||||
})
|
||||
# Create a path column
|
||||
PATH: list[str] = ["continent", "country", "city"]
|
||||
COLUMNS: list[str] = [None] * (len(PATH) - 2) + ["parent", "child"]
|
||||
|
||||
rollups = []
|
||||
base = df.groupby(PATH).sum(numeric_only=True)
|
||||
for level in range(len(PATH)):
|
||||
rollup = base.groupby(None, level=list(range(level + 1))).sum()
|
||||
rollup = rollup.reset_index(list(range(level + 1)), names=COLUMNS[-level - 1:])
|
||||
rollups.append(rollup)
|
||||
rollups = pd.concat(rollups, axis=0)
|
||||
|
||||
sb = Sunburst(labels=rollups["child"], parents=rollups["parent"], values=rollups["sales"], textinfo="label+value+percent parent", texttemplate="%{label}<br>%{value:,.2f}€", branchvalues="total")
|
||||
fig: Figure = Figure(sb, layout={
|
||||
"font": {"family": "Cabin", "size": 13},
|
||||
"margin": {"l": 0, "r": 0, "b": 0, "t": 0}
|
||||
})
|
||||
fig.show(renderer="browser")
|
||||
@@ -17,5 +17,9 @@ if __name__ == '__main__':
|
||||
})
|
||||
plot = sunburst(df, path=["country", "city"], values="sales", title="Sales by country and city", template="ggplot2",
|
||||
color_discrete_sequence=plotly.colors.qualitative.Dark2)
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
|
||||
plot.show()
|
||||
sb = next(plot.select_traces(row=0, col=0))
|
||||
sb.textinfo="label+percent parent"
|
||||
# sb.texttemplate="%{label}<br>%{value:.2f}€"
|
||||
plot.layout.update({"font": {"family": "Cabin", "size": 13}, "showlegend": True})
|
||||
# plot.update_traces(textinfo="label+percent parent", texttemplate="%{label}<br>%{value:.2f}€")
|
||||
plot.show(renderer="browser")
|
||||
|
||||
9
source/plotting/charts/plotly_template_select.py
Normal file
9
source/plotting/charts/plotly_template_select.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from plotly.express import bar
|
||||
import pandas as pd
|
||||
|
||||
data = pd.DataFrame({
|
||||
"product": ["stylo", "clavier", "souris", "écran"],
|
||||
"price": [1.99, 15.99, 8.99, 129.99],
|
||||
})
|
||||
figure = bar(data, x="product", y="price", title="Prix", template="seaborn")
|
||||
figure.show(renderer="browser")
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Reference in New Issue
Block a user