Compilateur LaTeX en ligne
www.cpierquet.fr
fichiers/c.pierquet/statspgfplots.tex
↓ télécharger
%!TEX pdflatex

\documentclass[11pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{pgfplots}
\usepackage{xint-regression}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows,arrows.meta,intersections,calc}

\begin{document}

\begin{tikzpicture}
	\begin{axis}%
		[%
		axis y line=center,axis x line=middle,                                   %axes
		axis line style={line width=0.8pt,-latex},
		x=0.3cm,y=0.5cm,xmin=1985,xmax=2030,ymin=56,ymax=70,                     %unités
		grid=both,xtick distance=5,ytick distance=2,                             %grillep
		minor x tick num=4,minor y tick num=1,                                   %grilles
		extra x ticks={1985},extra x tick style={grid=none},                     %originex
		extra y ticks={56},extra y tick style={grid=none},                       %originey
		x tick label style={/pgf/number format/.cd,use comma,1000 sep={}},       %année
		major tick length={2*3pt},minor tick length={1.5*3pt},                   %grads
		every tick/.style={line width=0.8pt},enlargelimits=false,                %style
		enlarge x limits={abs=2.5mm,upper},enlarge y limits={abs=2.5mm,upper},   %élargir
		x label style={anchor=west},y label style={anchor=south},                %labels axes
		xlabel={Année},ylabel={Population}
		]
		%stats avec xint-regression
		\def\LISTEXX{1990,1995,2000,2005,2010,2015,2020}%
		\def\LISTEYY{58,59.3,60.5,62.7,64.6,66.4,67.4}%
		\xintlinreg{\LISTEXX}{\LISTEYY}%
		%tracés de la droite de régression
		\addplot[name path global=dtereglin,mark=none,blue,line width=1.05pt,domain=1985:2030,samples=2] {\linrega*x+\linregb};
		%tracés des pints du nuage
		\addplot[mark=x,mark size=3pt,only marks,red,line width=0.95pt] coordinates {(1990,58) (1995,59.3) (2000,60.5) (2005,62.7) (2010,64.6) (2015,66.4) (2020,67.4)} ;
		%---> travail sur y=64
		%tracé de y=64
		\addplot[name path global=anteced,mark=none,olive,line width=1.05pt,domain=1985:2030,samples=2] {64} ;
		%recherche d'antécédents
		\path[name intersections={of=dtereglin and anteced,name=MonItsc}] ;
		%extraction des coordonnées
		\path \pgfextra{\pgfplotspointgetcoordinates{(MonItsc-1)}\pgfkeysgetvalue{/data point/x}{\tmpxgetvalue}\xdef\xMonItsc{\tmpxgetvalue}\pgfkeysgetvalue{/data point/y}{\tmpygetvalue}\xdef\yMonItsc{\tmpygetvalue}} ;
		%visualisation
		\draw[line width=0.9pt,densely dashed,olive,->,>=latex] (MonItsc-1)--(\xMonItsc,56) ;
		\filldraw[olive] (MonItsc-1) circle[radius=1.75pt] ;
	\end{axis}
\end{tikzpicture}

\end{document}