% proflycee-tools-stats.tex
% Copyright 2023  Cédric Pierquet
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.

%2.6.8	Grille histogrammes non réguliers
%2.6.7	Histogrammes

%%------RegressionLinéaire
%calcul des paramètres
\defKV[coeffreglin]{%
	NomCoeffa=\def\RegLinCoeffa{#1},%
	NomCoeffb=\def\RegLinCoeffb{#1},%
	NomCoeffr=\def\RegLinCoeffr{#1},%
	NomCoeffrd=\def\RegLinCoeffrd{#1},%
	NomXmin=\def\RegLinCoeffXmin{#1},%
	NomXmax=\def\RegLinCoeffXmax{#1}
}

\setKVdefault[coeffreglin]{%
	NomCoeffa=COEFFa,%
	NomCoeffb=COEFFb,%
	NomCoeffr=COEFFr,%
	NomCoeffrd=COEFFrd,%
	NomXmin=LXmin,%
	NomXmax=LXmax
}

\newcommand\CalculsRegLin[3][]{%
	\useKVdefault[coeffreglin]%
	\setKV[coeffreglin]{#1}% on paramètres les nouvelles clés et on les simplifie
	%xmin et xmax
	\expandafter\def\csname\RegLinCoeffXmin\endcsname{\fpeval{min(#2)}}
	\expandafter\def\csname\RegLinCoeffXmax\endcsname{\fpeval{max(#2)}}
	%listes des données
	\def\xliste{#2}
	\def\yliste{#3}
	\readlist*\LX{\xliste}
	\readlist*\LY{\yliste}
	%taille des listes
	\def\LNB{\inteval{\LXlen}}
	%somme des LX et des LY OK
	\xdef\LXSomme{0}
	\xdef\LYSomme{0}
	\foreach \i in {1,2,...,\LNB}{
		\xdef\LXSomme{\fpeval{\LXSomme+\LX[\i]}}
	}
	\foreach \i in {1,2,...,\LNB}{
		\xdef\LYSomme{\fpeval{\LYSomme+\LY[\i]}}
	}
	%moyenne des LX et des LY OK
	\xdef\LXmoy{\fpeval{\LXSomme/\LNB}}
	\xdef\LYmoy{\fpeval{\LYSomme/\LNB}}
	%variance des LX et des LY OK
	\xdef\LXvar{0}
	\foreach \i in {1,2,...,\LNB}{
		\xdef\LXvar{\fpeval{\LXvar+(\LX[\i]-\LXmoy)*(\LX[\i]-\LXmoy)}}
	}
	\xdef\LXvar{\fpeval{\LXvar/\LNB}}
	\xdef\LYvar{0}
	\foreach \i in {1,2,...,\LNB}{
		\xdef\LYvar{\fpeval{\LYvar+(\LY[\i]-\LYmoy)*(\LY[\i]-\LYmoy)}}
	}
	\xdef\LYvar{\fpeval{\LYvar/\LNB}}
	%covariance des XY OK
	\xdef\LXYvar{0}
	\foreach \i in {1,2,...,\LNB}{
		\xdef\LXYvar{\fpeval{\LXYvar+(\LX[\i]-\LXmoy)*(\LY[\i]-\LYmoy)}}
	}
	\xdef\LXYvar{\fpeval{\LXYvar/\LNB}}
	%COEFFS OK
	\expandafter\def\csname\RegLinCoeffa\endcsname{\fpeval{\LXYvar/\LXvar}}
	\expandafter\def\csname\RegLinCoeffb\endcsname{\fpeval{\LYmoy-\csname\RegLinCoeffa\endcsname*\LXmoy}}
	\expandafter\def\csname\RegLinCoeffr\endcsname{\fpeval{\LXYvar/sqrt(\LXvar*\LYvar)}}
	\expandafter\def\csname\RegLinCoeffrd\endcsname{\fpeval{\csname\RegLinCoeffr\endcsname*\csname\RegLinCoeffr\endcsname}}
}

%pour un nuage en TiKz
\defKV[nuagereglin]{%
	Couleur=\def\RegLinNuageCouleur{#1},%
	Taille=\def\RegLinNuageTaille{#1},
	Ox=\def\RegLinNuageOx{#1},%
	Oy=\def\RegLinNuageOy{#1},%
}

\setKVdefault[nuagereglin]{%
	Couleur=teal,%
	Taille=2pt,%
	Ox=0,%
	Oy=0
}

\newcommand\PointsRegLin[3][]{%
	\useKVdefault[nuagereglin]
	\setKV[nuagereglin]{#1}% on paramètres les nouvelles clés et on les simplifie
	\def\xliste{#2}
	\def\yliste{#3}
	\readlist*\LX{\xliste}
	\readlist*\LY{\yliste}
	%taille des listes
	\def\LNB{\inteval{\LXlen}}
	\foreach \i in {1,2,...,\LNB} {\filldraw[\RegLinNuageCouleur] ({\LX[\i]-\RegLinNuageOx},{\LY[\i]-\RegLinNuageOy}) circle[radius=\RegLinNuageTaille] ;}
}

\NewDocumentEnvironment{StatsTikz}{ O{} }
{%
	\begin{tikzpicture}[#1]
	}%
	{%
	\end{tikzpicture}%
}

%%------BOITES MOUSTACHES
\defKV[boiteamoustaches]{%
	Couleur=\def\BaMCouleur{#1},%
	Elevation=\def\BaMElevation{#1},%
	Hauteur=\def\BaMHauteur{#1},%
	Moyenne=\def\BaMMoyenne{#1},%
	Epaisseur=\def\BaMEpaisseur{#1},%
	Remplir=\def\BaMRemplissage{#1}
}

\setKVdefault[boiteamoustaches]{%
	Couleur=black,%
	Elevation=1,%
	Hauteur=1,%
	AffMoyenne=false,%
	Epaisseur=thick,%
	Pointilles=false,%
	Valeurs=false,%
	Remplir=white
}

\defKV[boiteamoustachesaxe]{%
	Min=\def\BaMAxeMin{#1},%
	Max=\def\BaMAxeMax{#1},%
	Elargir=\def\BaMAxeElarg{#1},%
	Epaisseur=\def\BaMAxeEpaisseur{#1},%
	Valeurs=\def\BaMAxeValeurs{#1}
}

\setKVdefault[boiteamoustachesaxe]{%
	Elargir=0.05,%
	Epaisseur=thick,%
	AffValeurs=false
}

\newcommand\BoiteMoustachesAxe[1][]{
	\useKVdefault[boiteamoustachesaxe]
	\setKV[boiteamoustachesaxe]{#1}
	\def\BaMaxelargeur{\fpeval{\BaMAxeMax-\BaMAxeMin}}
	\def\BaMaxexmin{\fpeval{\BaMAxeMin-\BaMAxeElarg*\BaMaxelargeur}}
	\def\BaMaxexmax{\fpeval{\BaMAxeMax+\BaMAxeElarg*\BaMaxelargeur}}
	\draw[\BaMAxeEpaisseur,->,>=latex] (\BaMaxexmin,0) -- (\BaMaxexmax,0) ;
	\ifboolKV[boiteamoustachesaxe]{AffValeurs}
		{\foreach \x in \BaMAxeValeurs \draw[\BaMAxeEpaisseur] (\x,3pt)--(\x,-3pt) node[below=3pt] {\num{\x}} ;}
		{}
}

\newcommand\BoiteMoustaches[2][]{
	\useKVdefault[boiteamoustaches]
	\setKV[boiteamoustaches]{#1}
	\setsepchar[.]{/}%
	\readlist*\BaMListeparams{#2}%
	\itemtomacro\BaMListeparams[1]\BaMmin%
	\itemtomacro\BaMListeparams[2]\BaMqu%
	\itemtomacro\BaMListeparams[3]\BaMmed%
	\itemtomacro\BaMListeparams[4]\BaMqt%
	\itemtomacro\BaMListeparams[5]\BaMmax%
	\draw[draw,\BaMEpaisseur,\BaMCouleur,fill=\BaMRemplissage] ({\BaMqu},{\BaMElevation-0.5*\BaMHauteur}) rectangle ({\BaMqt},{\BaMElevation+0.5*\BaMHauteur}) ;
	\draw[\BaMEpaisseur,\BaMCouleur] (\BaMmin,{\BaMElevation-0.5*\BaMHauteur})--(\BaMmin,{\BaMElevation+0.5*\BaMHauteur}) (\BaMmax,{\BaMElevation-0.5*\BaMHauteur})--(\BaMmax,{\BaMElevation+0.5*\BaMHauteur}) (\BaMmed,{\BaMElevation-0.5*\BaMHauteur})--(\BaMmed,{\BaMElevation+0.5*\BaMHauteur});
	\draw[\BaMEpaisseur,\BaMCouleur] ({\BaMmin},{\BaMElevation})--({\BaMqu},{\BaMElevation}) ({\BaMqt},{\BaMElevation})--({\BaMmax},{\BaMElevation}) ;
	\ifboolKV[boiteamoustaches]{AffMoyenne}
		{\filldraw[\BaMCouleur] ({\BaMMoyenne},{\BaMElevation}) circle[radius=2.5pt] ;}
		{}
	\ifboolKV[boiteamoustaches]{Pointilles}
		{
			\draw[\BaMEpaisseur,densely dashed] (\BaMmin,{\BaMElevation-0.5*\BaMHauteur}) -- (\BaMmin,0) ;
			\draw[\BaMEpaisseur,densely dashed] (\BaMqu,{\BaMElevation-0.5*\BaMHauteur}) -- (\BaMqu,0) ;
			\draw[\BaMEpaisseur,densely dashed] (\BaMmed,{\BaMElevation-0.5*\BaMHauteur}) -- (\BaMmed,0) ;
			\draw[\BaMEpaisseur,densely dashed] (\BaMqt,{\BaMElevation-0.5*\BaMHauteur}) -- (\BaMqt,0) ;
			\draw[\BaMEpaisseur,densely dashed] (\BaMmax,{\BaMElevation-0.5*\BaMHauteur}) -- (\BaMmax,0) ;
		}
		{}
	\ifboolKV[boiteamoustaches]{Valeurs}
		{
			\filldraw (\BaMmin,0) circle[radius=2pt] node[below=4pt] {\num{\BaMmin}} ;
			\filldraw (\BaMqu,0) circle[radius=2pt] node[below=4pt] {\num{\BaMqu}} ;
			\filldraw (\BaMmed,0) circle[radius=2pt] node[below=4pt] {\num{\BaMmed}} ;
			\filldraw (\BaMqt,0) circle[radius=2pt] node[below=4pt] {\num{\BaMqt}} ;
			\filldraw (\BaMmax,0) circle[radius=2pt] node[below=4pt] {\num{\BaMmax}} ;
		}
		{}
}

%%------HISTOGRAMME
\defKV[histostats]{%
	ListeCouleurs=\def\HistoCouleurs{#1},%
	Largeur=\def\HistoLargeur{#1},%
	Hauteur=\def\HistoHauteur{#1},%
	GradX=\def\HistoGradX{#1},%
	GradY=\def\HistoGradY{#1},%
	PosEffectifs=\def\HistoPosEff{#1},%
	LabelX=\def\HistoLabelx{#1},%
	LabelY=\def\HistoLabely{#1},%
	ElargirX=\def\HistoElargirx{#1},%
	ElargirY=\def\HistoElargiry{#1},%
	PoliceAxes=\def\HistoFonte{#1},%
	PoliceEffectifs=\def\HistoFonteEff{#1},%
	Opacite=\def\HistoOpac{#1},%
	DebutOx=\def\HistoDebX{#1},%
	FinOx=\def\HistoFinX{#1},%
	EpaisseurTraits=\def\HistoEptraits{#1},%
	Grille=\def\HistoGrille{#1},%
	ExtraGrilleY=\def\HistoExtraGridY{#1},%
	PosLegende=\def\HistoPosLeg{#1}
}

\setKVdefault[histostats]{%
	ListeCouleurs=orange,%
	Largeur=10,%
	Hauteur=5,%
	GradX={},%
	GradY={},%
	AffEffectifs=true,%
	PosEffectifs=milieu,%
	ElargirX=5mm,%
	ElargirY=5mm,%
	LabelX={},%
	LabelY={},%
	PoliceAxes=\normalsize\normalfont,%
	PoliceEffectifs=\normalsize\normalfont,%
	AffBornes=false,%
	Remplir=true,%
	Opacite=0.5,%
	GrilleV=true,%
	DebutOx={},%
	FinOx={},%
	EpaisseurTraits=semithick,%
	Grille={},%
	ExtraGrilleY=0,%
	PosLegende={}
}

\NewDocumentCommand\Histogramme{ s O{} m }{%
	\useKVdefault[histostats]%
	\setKV[histostats]{#2}%
	\setsepchar[.]{ ./}%
	\readlist*\LISTDONNEES{#3}%
	\IfEq{\HistoDebX}{}%on stocke le début de l'axe Ox si besoin
		{\itemtomacro\LISTDONNEES[1,1]{\HistoDebX}}{}%
	\IfEq{\HistoFinX}{}%on stocke la fin de l'axe Ox si besoin
		{\itemtomacro\LISTDONNEES[-1,2]{\HistoFinX}}{}%
	\setsepchar{,}%
	\readlist*\LISTCOUL{\HistoCouleurs}%
	%distinction suivant largeur classes
	\IfBooleanTF{#1}%étoilé := classe d'amplitudes différentes
		{%
			
			\xdef\ListeHauteurs{\xintfloateval{(\LISTDONNEES[1,3])/(\LISTDONNEES[1,2]-\LISTDONNEES[1,1])}}
			\foreach \i in {2,...,\LISTDONNEESlen}
				{%
					\xdef\ListeHauteurs{\ListeHauteurs,\xintfloateval{(\LISTDONNEES[\i,3])/(\LISTDONNEES[\i,2]-\LISTDONNEES[\i,1])}}%
				}%
			\IfEq{\HistoGrille}{}%on lit les infos de la grille PasX/UniteAire
				{}%
				{%
					\StrCut{\HistoGrille}{/}{\HistoPasX}{\HistoUnAire}%
					\def\HistoPasY{\xintfloateval{\HistoUnAire/\HistoPasX}}%
				}%
			\xdef\maxhauteurs{\xintfloateval{round(max(\ListeHauteurs),3)}}%
			
			\IfEq{\HistoGrille}{}%
				{%
					\xdef\HistoUniteY{\xintfloateval{round(\HistoHauteur/max(\ListeHauteurs),3)}}%
				}%
				{%
					\xdef\maxhauteurgrille{\xinteval{(floor((\maxhauteurs)/(\HistoPasY))+1+\HistoExtraGridY)*\HistoPasY}}%
					\xdef\HistoUniteY{\xintfloateval{round((\HistoHauteur)/(\maxhauteurgrille),3)}}%
				}%
			\xdef\HistoUniteX{\xintfloateval{round(\HistoLargeur/(\HistoFinX-\HistoDebX),3)}}%
			%fenêtre graphique
			\begin{tikzpicture}[x=\HistoUniteX cm,y=\HistoUniteY cm]
				%Essai de grille
				\IfEq{\HistoGrille}{}%
					{}%
					{%
						\draw[line width=0.4pt,lightgray,xstep=\HistoPasX,ystep=\HistoPasY] ({\HistoDebX},0) grid ({\HistoFinX},{\xinteval{floor((\maxhauteurs)/(\HistoPasY))+1+\HistoExtraGridY}*\HistoPasY}) ;
						\IfSubStr{\HistoPosLeg}{/}%
							{%
								\StrCut{\HistoPosLeg}{/}{\HistoPosLegX}{\HistoPosLegY}%
								\draw[\HistoEptraits,fill=lightgray,fill opacity=\HistoOpac] ({\HistoDebX+(\HistoPosLegX)*(\HistoPasX)},{(\HistoPasY)*(\HistoPosLegY)}) rectangle++ ({\HistoPasX},{\HistoPasY}) ; %
								\draw ({\HistoDebX+(\HistoPosLegX+1)*(\HistoPasX)},{(\HistoPasY)*(\HistoPosLegY+0.5)}) node[right,font=\HistoFonteEff] {\num{\HistoUnAire}} ;%
							}%
							{}%
						%\draw ({\HistoDebX},{0}) node[below left] {\xinteval{floor((\maxhauteurs)/(\HistoPasY))+1}} ;
						%\draw ({\HistoDebX},{\HistoPasY}) node[left] {\num{\HistoPasY}} ;
						%\draw ({\HistoDebX},{\maxhauteurs}) node[left] {\num{\maxhauteurs}} ;
						
					}%
				%rectangles
				\foreach \i in {1,...,\LISTDONNEESlen}
					{%
						\xintifboolexpr{\LISTCOULlen == 1}%
							{\def\couleurhisto{\HistoCouleurs}}%
							{\itemtomacro\LISTCOUL[\i]{\couleurhisto}}%
						\ifboolKV[histostats]{AffBornes}%
							{%
								\draw[\HistoEptraits] ({\LISTDONNEES[\i,1]},3pt)--++(0,-6pt) node[below,font=\HistoFonte] {\LISTDONNEES[\i,1]} ;
								\draw[\HistoEptraits] ({\LISTDONNEES[\i,2]},3pt)--++(0,-6pt) node[below,font=\HistoFonte] {\LISTDONNEES[\i,2]} ;
							}%
							{}%
						\ifboolKV[histostats]{Remplir}%
							{%
								\draw[\HistoEptraits,fill=\couleurhisto,fill opacity=\HistoOpac] ({\LISTDONNEES[\i,1]},0) rectangle ({\LISTDONNEES[\i,2]},{(\LISTDONNEES[\i,3])/(\LISTDONNEES[\i,2]-\LISTDONNEES[\i,1])}) ;
							}%
							{%
								\draw[\HistoEptraits] ({\LISTDONNEES[\i,1]},0) rectangle ({\LISTDONNEES[\i,2]},{(\LISTDONNEES[\i,3])/(\LISTDONNEES[\i,2]-\LISTDONNEES[\i,1])}) ;
							}%
					}%
				\foreach \x in \HistoGradX
					{%
						\draw[\HistoEptraits] (\x,3pt)--++(0,-6pt) node[below,font=\HistoFonte] {\num{\x}} ;
					}%
				\ifboolKV[histostats]{AffEffectifs}
					{%
						\IfStrEq{\HistoPosEff}{milieu}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{0.5*(\LISTDONNEES[\i,3])/(\LISTDONNEES[\i,2]-\LISTDONNEES[\i,1])}) node[font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
						\IfStrEq{\HistoPosEff}{bas}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{0}) node[above,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
						\IfStrEq{\HistoPosEff}{haut}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{(\LISTDONNEES[\i,3])/(\LISTDONNEES[\i,2]-\LISTDONNEES[\i,1])}) node[below,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
						\IfStrEq{\HistoPosEff}{dessus}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{(\LISTDONNEES[\i,3])/(\LISTDONNEES[\i,2]-\LISTDONNEES[\i,1])}) node[above,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
					}%
					{}%
				\draw[\HistoEptraits,->,>=latex] ({\HistoDebX},0) -- ({\HistoFinX},0) --++ ({\HistoElargirx},0) node[right,font=\HistoFonte] {\HistoLabelx} ;
			\end{tikzpicture}%
		}%
		{%
			\xdef\ListeHauteurs{\LISTDONNEES[1,3]}
			\foreach \i in {2,...,\LISTDONNEESlen}
				{%
					\xdef\ListeHauteurs{\ListeHauteurs,\LISTDONNEES[\i,3]}%
				}%
			\xdef\maxhauteurs{\xinteval{round(max(\ListeHauteurs),3)}}%
			\xdef\HistoUniteY{\xinteval{round(\HistoHauteur/max(\ListeHauteurs),3)}}%
			\xdef\HistoUniteX{\xinteval{round(\HistoLargeur/(\HistoFinX-\HistoDebX),3)}}%
			%fenêtre graphique
			\begin{tikzpicture}[x=\HistoUniteX cm,y=\HistoUniteY cm]
				\ifboolKV[histostats]{GrilleV}%
					{%
						\foreach \y in \HistoGradY
						{%
							\draw[line width=0.4pt,lightgray] ({\HistoDebX},\y) -- ({\HistoFinX},\y) --++ ({\HistoElargirx},0) ;
						}%
					}%
					{}%
				\foreach \i in {1,...,\LISTDONNEESlen}
					{%
						\xintifboolexpr{\LISTCOULlen == 1}%
							{\def\couleurhisto{\HistoCouleurs}}%
							{\itemtomacro\LISTCOUL[\i]{\couleurhisto}}%
						\ifboolKV[histostats]{AffBornes}%
							{%
								\draw[\HistoEptraits] ({\LISTDONNEES[\i,1]},3pt)--++(0,-6pt) node[below,font=\HistoFonte] {\LISTDONNEES[\i,1]} ;
								\draw[\HistoEptraits] ({\LISTDONNEES[\i,2]},3pt)--++(0,-6pt) node[below,font=\HistoFonte] {\LISTDONNEES[\i,2]} ;
							}%
							{}%
						\ifboolKV[histostats]{Remplir}%
						{%
							\draw[\HistoEptraits,fill=\couleurhisto,fill opacity=\HistoOpac] ({\LISTDONNEES[\i,1]},0) rectangle ({\LISTDONNEES[\i,2]},{\LISTDONNEES[\i,3]}) ;
						}%
						{%
							\draw[\HistoEptraits] ({\LISTDONNEES[\i,1]},0) rectangle ({\LISTDONNEES[\i,2]},{\LISTDONNEES[\i,3]}) ;
						}%
					}%
				\foreach \x in \HistoGradX
					{%
						\draw[\HistoEptraits] (\x,3pt)--++(0,-6pt) node[below,font=\HistoFonte] {\num{\x}} ;
					}%
				\foreach \y in \HistoGradY
					{%
						\draw[\HistoEptraits] ($({\HistoDebX},\y)+(3pt,0)$) --++ (-6pt,0) node[left,font=\HistoFonte] {\num{\y}} ;
					}%
				\ifboolKV[histostats]{AffEffectifs}
					{%
						\IfStrEq{\HistoPosEff}{milieu}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{0.5*\LISTDONNEES[\i,3]}) node[font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
						\IfStrEq{\HistoPosEff}{bas}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{0}) node[above,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
						\IfStrEq{\HistoPosEff}{haut}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{\LISTDONNEES[\i,3]}) node[below,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
						\IfStrEq{\HistoPosEff}{dessus}%
							{%
								\foreach \i in {1,...,\LISTDONNEESlen}
									\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]},{\LISTDONNEES[\i,3]}) node[above,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
							}%
							{}%
					}%
					{}%
			\draw[\HistoEptraits,->,>=latex] ({\HistoDebX},0) -- ({\HistoFinX},0) --++ ({\HistoElargirx},0) node[right,font=\HistoFonte] {\HistoLabelx} ;
			\draw[\HistoEptraits,->,>=latex] ({\HistoDebX},0) -- ({\HistoDebX},{\maxhauteurs}) --++ (0,{\HistoElargiry}) node[above,font=\HistoFonte] {\HistoLabely} ;
		\end{tikzpicture}%
		}%
}

\NewDocumentCommand\HistogrammeTikz{ O{} m }{%
	\useKVdefault[histostats]%
	\setKV[histostats]{#1}%
	\setsepchar[.]{ ./}%
	\readlist*\LISTDONNEES{#2}%
	\setsepchar{,}%
	\readlist*\LISTCOUL{\HistoCouleurs}%
	\foreach \i in {1,...,\LISTDONNEESlen}
		{%
			\xintifboolexpr{\LISTCOULlen == 1}%
				{\def\couleurhisto{\HistoCouleurs}}%
				{\itemtomacro\LISTCOUL[\i]{\couleurhisto}}%
		\ifboolKV[histostats]{Remplir}%
			{%
				\draw[line width=1pt,fill=\couleurhisto,fill opacity=\HistoOpac] ({\LISTDONNEES[\i,1]-\axexOx},0) rectangle ({\LISTDONNEES[\i,2]-\axexOx},{\LISTDONNEES[\i,3]}) ;
			}%
			{%
				\draw[line width=1pt] ({\LISTDONNEES[\i,1]-\axexOx},0) rectangle ({\LISTDONNEES[\i,2]-\axexOx},{\LISTDONNEES[\i,3]}) ;
			}%
		}%
	\ifboolKV[histostats]{AffEffectifs}
		{%
			\IfStrEq{\HistoPosEff}{milieu}%
				{%
					\foreach \i in {1,...,\LISTDONNEESlen}
						\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]-\axexOx},{0.5*\LISTDONNEES[\i,3]}) node[font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
				}%
				{}%
			\IfStrEq{\HistoPosEff}{bas}%
				{%
					\foreach \i in {1,...,\LISTDONNEESlen}
						\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]-\axexOx},{0}) node[above,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
				}%
				{}%
			\IfStrEq{\HistoPosEff}{haut}%
				{%
					\foreach \i in {1,...,\LISTDONNEESlen}
						\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]-\axexOx},{\LISTDONNEES[\i,3]}) node[below,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
				}%
				{}%
			\IfStrEq{\HistoPosEff}{dessus}%
				{%
					\foreach \i in {1,...,\LISTDONNEESlen}
						\draw ({0.5*\LISTDONNEES[\i,1]+0.5*\LISTDONNEES[\i,2]-\axexOx},{\LISTDONNEES[\i,3]}) node[above,font=\HistoFonteEff] {\num{\LISTDONNEES[\i,3]}} ;
				}%
				{}%
		}%
		{}%
}

\endinput