Add source example files

This commit is contained in:
2025-07-12 18:43:56 +02:00
parent 11d6846f49
commit d0bcfcf8f1
62 changed files with 40101 additions and 161 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -0,0 +1,21 @@
from typing import Iterable
from matplotlib import pyplot as plot
from matplotlib.axes import Axes
from matplotlib.figure import Figure
import matplotlib
if __name__ == '__main__':
matplotlib.use("QtCairo")
labels: Iterable[str] = ("Janvier", "Février", "Mars", "Avril")
values: Iterable[float] = (50, 11.4, 91, 66.1)
figure: Figure
axis: Axes
figure, axis = plot.subplots(nrows=1, ncols=1)
axis.bar(x=labels, height=values, color="#00ff00")
circle = plot.Circle((2, 20), 2, color="#FF0000", fill=False)
axis.set_ylabel("Précipitations (mm)")
axis.set_xlabel("Mois")
axis.set_title("Précipitations pour 2022")
axis.add_artist(circle)
plot.show()

View File

@ -0,0 +1,19 @@
from typing import Iterable
from matplotlib import pyplot as plot
from matplotlib.axes import Axes
from matplotlib.figure import Figure
import matplotlib
if __name__ == '__main__':
matplotlib.use("QtCairo")
labels: Iterable[str] = ("Janvier", "Février", "Mars", "Avril")
values: Iterable[float] = (50, 11.4, 91, 66.1)
figure: Figure
axis: Axes
figure, axis = plot.subplots(nrows=1, ncols=1)
axis.bar(x=labels, height=values, color="#00ff00")
axis.set_ylabel("Précipitations (mm)")
axis.set_xlabel("Mois")
axis.set_title("Précipitations pour 2022")
figure.savefig("bar-chart.png", transparent=True)

View File

@ -0,0 +1,24 @@
"""
Display sales of various cities in a sunburst chart.
Given the cities can have recurring parents, we can have
a sunburst chart with 2 rings, the centermost ring for the
country, and the outmost ring to have sales per city.
"""
import matplotlib
import pandas as pd
from matplotlib import pyplot
if __name__ == '__main__':
matplotlib.use("QtCairo")
df = pd.DataFrame(data={
"country": ["France", "France", "Spain", "Spain"],
"city": ["Montpellier", "Bordeaux", "Madrid", "Valencia"],
"sales": [150_000, 127_000, 97_200, 137_250]
})
df.set_index(["country", "city"], inplace=True)
total: int = df["sales"].sum()
print(df)
axes = df.plot.pie(subplots=True, autopct=lambda x: f"{x * total / 100:.0f} {x:.2f}%")
pyplot.show()

View File

@ -0,0 +1,8 @@
import pandas as pd
from plotly.express import bar
if __name__ == '__main__':
df = pd.DataFrame(data={"label": ["Citron", "Pomme", "Mangue"], "price": [1.99, 3.97, 6.8]})
plot = bar(df, x="label", y="price")
plot.show()

View File

@ -0,0 +1,11 @@
import pandas as pd
from plotly import express as px
data = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data", header=None,
names=["sepal-length", "sepal-width", "petal-length", "petal-width", "class"])
plot = px.scatter(data, x="sepal-length", y="sepal-width", size="petal-width", color="class", template="seaborn",
title="Iris flowers dataset",
labels={"sepal-length": "Sepal length", "sepal-width": "Sepal width", "petal-width": "Petal width", "class": "Class"})
plot.layout.update({"font": {"family": "Cabin", "size": 13}})
plot.show()

View File

@ -0,0 +1,21 @@
"""
Display sales of various cities in a sunburst chart.
Given the cities can have recurring parents, we can have
a sunburst chart with 2 rings, the centermost ring for the
country, and the outmost ring to have sales per city.
"""
import pandas as pd
import plotly
from plotly.express import sunburst
if __name__ == '__main__':
df = pd.DataFrame(data={
"country": ["France", "France", "Spain", "Spain", "England", "England", "England"],
"city": ["Montpellier", "Bordeaux", "Madrid", "Valencia", "London", "Manchester", "Bristol"],
"sales": [150_000, 127_000, 97_200, 137_250, 200_000, 180_000, 150_000]
})
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()