Add source example files
This commit is contained in:
25
source/plotting/agg-pie.py
Normal file
25
source/plotting/agg-pie.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pandas as pd
|
||||
from matplotlib import use, pyplot
|
||||
|
||||
# Utiliser tkinter
|
||||
use("TkAgg")
|
||||
pyplot.style.use('ggplot')
|
||||
pyplot.rcParams["font.family"] = "Cabin"
|
||||
|
||||
# Données à afficher
|
||||
data = pd.DataFrame(data={
|
||||
"product": ["pomme", "poire", "banane", "pêche"],
|
||||
"price": [1.99, 2.49, 2.99, 3.49]
|
||||
})
|
||||
|
||||
|
||||
def sector_label(pct: float) -> str:
|
||||
value = pct * sum(data["price"]) / 100
|
||||
return f"{value:.1f}€\n{pct:.1f}%"
|
||||
|
||||
|
||||
# Générer un graphique dans Matplotlib
|
||||
axis = data.set_index("product").plot.pie(y="price", title="Prix", autopct=sector_label)
|
||||
# Afficher le dernier graphique généré
|
||||
axis.figure.savefig("eda-matplotlib-pie-themed.png")
|
||||
pyplot.show()
|
Reference in New Issue
Block a user