Charte commune (style.py), générateur SVG/PNG (generer.py) et 4 figures pour le module PWM & ADC : rapport cyclique, servo 50 Hz, montage du variateur, quantification ADC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""Charte graphique commune à tous les schémas de la formation."""
|
|
from dataclasses import dataclass
|
|
from typing import Callable
|
|
|
|
import matplotlib
|
|
|
|
matplotlib.use("Agg")
|
|
import matplotlib.pyplot as plt # noqa: E402
|
|
|
|
# Palette
|
|
BLEU = "#1f5fa8" # signal principal
|
|
ORANGE = "#e07a1f" # valeur moyenne, mise en évidence
|
|
VERT = "#2e8b57"
|
|
ROUGE = "#c0392b"
|
|
GRIS = "#6b7280"
|
|
GRIS_CLAIR = "#e5e7eb"
|
|
ENCRE = "#1f2937" # texte
|
|
|
|
CM = 1 / 2.54 # conversion cm -> pouces pour figsize
|
|
|
|
plt.rcParams.update({
|
|
"font.family": "DejaVu Sans",
|
|
"font.size": 10,
|
|
"axes.edgecolor": GRIS,
|
|
"axes.labelcolor": ENCRE,
|
|
"axes.titlesize": 11,
|
|
"axes.titleweight": "bold",
|
|
"axes.titlecolor": ENCRE,
|
|
"axes.spines.top": False,
|
|
"axes.spines.right": False,
|
|
"axes.grid": True,
|
|
"grid.color": GRIS_CLAIR,
|
|
"grid.linewidth": 0.8,
|
|
"xtick.color": GRIS,
|
|
"ytick.color": GRIS,
|
|
"lines.linewidth": 2,
|
|
"svg.fonttype": "path", # texte vectorisé : rendu identique partout
|
|
"savefig.bbox": "tight",
|
|
"savefig.pad_inches": 0.1,
|
|
"savefig.facecolor": "white",
|
|
})
|
|
|
|
|
|
@dataclass
|
|
class Figure:
|
|
"""Déclaration d'une figure à générer puis insérer dans un support."""
|
|
id: str # ex. "m03-pwm-duty" ; le préfixe mXX donne le module
|
|
legende: str # texte de la légende (sans « Figure X.Y — »)
|
|
ancre: str # texte exact du titre de section concerné
|
|
dessiner: Callable # renvoie une figure matplotlib ou un dessin schemdraw
|
|
largeur_cm: float = 16.0
|