Explorer les Livres électroniques
Catégories
Explorer les Livres audio
Catégories
Explorer les Magazines
Catégories
Explorer les Documents
Catégories
Denis Bitouz
denis.bitouze@lmpa.univ-littoral.fr
http://gte.univ-littoral.fr/members/dbitouze/pub/latex
&
Laboratoire de Mathmatiques Pures et Appliques
Joseph Liouville
http://www-lmpa.univ-littoral.fr
Plan
1
Confrence LATEX no 10
2 / 70
Plan
1
Confrence LATEX no 10
3 / 70
Introduction
Confrence LATEX no 10
4 / 70
Introduction
Confrence LATEX no 10
5 / 70
Confrence LATEX no 10
6 / 70
Systme de coordonnes
2.5
2
1.5
(2, 1)
1
0.5
0
0.5
1.5
2.5
Confrence LATEX no 10
7 / 70
Systme de coordonnes
2.5
2
1.5
(2, 1)
1
0.5
0
0.5
1.5
2.5
Remarque
Lunit par dfaut est le cm
Ainsi, le point de coordonnes (2,1) est situ 2 cm droite et 1 cm
au-dessus de lorigine
Denis Bitouz (IUT GTE Dk & LMPA)
Confrence LATEX no 10
7 / 70
Premire approche
Confrence LATEX no 10
8 / 70
Premire approche
Attention !
Tout graphique (et plus gnralement toute dclaration) doit se
terminer par un point virgule
Confrence LATEX no 10
9 / 70
Premire approche
1 \begin{tikzpicture}
0.8
2 \begin{axis}
0.6
3 \end{axis}
4 \end{tikzpicture}
0.4
0.2
0
0
0.2
0.4
0.6
0.8
Remarque
Le carr de ct 1 1 est en fait lgrement augment
Confrence LATEX no 10
10 / 70
Confrence LATEX no 10
11 / 70
Construction directe
Code source
10
1 \begin{tikzpicture}
2 \begin{axis}
3 % Courbe
y = 10 x2
4 \addplot {10-x^2};
5 \end{axis}
10
6 \end{tikzpicture}
6
Remarque
Par dfaut, le domaine [5, 5] est utilis pour les abscisses et le
domaine pour les ordonnes est automatiquement adapt
Confrence LATEX no 10
12 / 70
Confrence LATEX no 10
13 / 70
Code source
100
1 \begin{tikzpicture}
80
2 \begin{axis}
60
3 \addplot coordinates {
40
20
0
0
0.5
1.5
Remarque
Les domaines pour les abscisses et pour les ordonnes est
automatiquement adapt aux donnes reprsenter
Denis Bitouz (IUT GTE Dk & LMPA)
Confrence LATEX no 10
14 / 70
Confrence LATEX no 10
15 / 70
Confrence LATEX no 10
16 / 70
100
Code source
\begin{tikzpicture}
\begin{axis}
\addplot file {data.txt};
\end{axis}
\end{tikzpicture}
80
60
40
20
0
0
Confrence LATEX no 10
0.5
1.5
2
17 / 70
x 1 y1
x 2 y2
...
Confrence LATEX no 10
18 / 70
Remarque
Les lignes commenant par # ou % sont ignores
Les donnes dune mme ligne sont spares par des espaces ou
tabulations
Remarque
Lalignement vertical est facultatif mais facilite la lecture
Confrence LATEX no 10
19 / 70
Remarque
La mthode de lecture partir dun fichier est simple mais limite
La mthode de lecture des donnes partir dun fichier peut tre
tendue au moyen de la mthode de lecture des donnes partir dun
tableau 2
Confrence LATEX no 10
20 / 70
Rep1
1
10
100
Rep2
1
0.1
0.01
Code source
1
2
3
4
5
6
\begin{tikzpicture}
\begin{axis}
\addplot table[x=Temps,y=Rep1]
{data1.txt};
\end{axis}
\end{tikzpicture}
100
80
60
40
20
0
0
Confrence LATEX no 10
0.5
1.5
2
21 / 70
Rep1
1
10
100
Rep2
1
0.1
0.01
Code source
1
2
3
4
5
6
\begin{tikzpicture}
\begin{axis}
\addplot table[x=Temps,y=Rep2]
{data1.txt};
\end{axis}
\end{tikzpicture}
1
0.8
0.6
0.4
0.2
0
0
Confrence LATEX no 10
0.5
1.5
2
22 / 70
Confrence LATEX no 10
23 / 70
Confrence LATEX no 10
24 / 70
Rep1
1
10
100
Rep2
1
0.1
0.01
Code source (x 7 x + 3)
1
2
3
4
5
6
7
8
9
\begin{tikzpicture}
\begin{axis}
\addplot table[%
x expr=\thisrow{Temps}+3,
y
=
Rep1
]
{data1.txt};
\end{axis}
\end{tikzpicture}
100
80
60
40
20
0
3
Confrence LATEX no 10
3.5
4.5
5
25 / 70
Temps,Rep1,Rep2
0,1,1
1,10,0.1
2,100,0.01
\begin{tikzpicture}
\begin{axis}
\addplot table[
x=Temps,y=Rep1,
col sep=comma
]
{data2.txt};
\end{axis}
\end{tikzpicture}
100
80
60
40
20
0
0
Confrence LATEX no 10
0.5
1.5
2
26 / 70
Confrence LATEX no 10
27 / 70
Confrence LATEX no 10
28 / 70
Dans TeXstudio :
1 stockage des donnes dans un fichier de texte brut :
1
2
3
4
5
3
+ C
Admiration du rsultat
3. Le sparateur dcimal des donnes doit tre le point, et non pas la virgule
Denis Bitouz (IUT GTE Dk & LMPA)
Confrence LATEX no 10
29 / 70
Confrence LATEX no 10
30 / 70
Autres graphiques
Confrence LATEX no 10
31 / 70
Autres graphiques
Graphique de dpart
(Sans option)
100
Code source
1 \begin{tikzpicture}
80
2 \begin{axis}
60
3 \addplot coordinates {
40
20
0
0
Confrence LATEX no 10
0.5
1.5
32 / 70
Autres graphiques
Nuages de points
Option only marks
100
Code source
1 \begin{tikzpicture}
80
2 \begin{axis}[only marks]
60
3 \addplot coordinates {
40
20
0
0
Confrence LATEX no 10
0.5
1.5
33 / 70
Autres graphiques
Diagrammes en rectangles
Option ybar
100
Code source
1 \begin{tikzpicture}
80
2 \begin{axis}[ybar]
60
3 \addplot coordinates {
40
20
0
0
0.5
1.5
Attention !
Diagrammes en rectangles , histogrammes
Confrence LATEX no 10
34 / 70
Autres graphiques
Diagrammes en rectangles
Option ybar
100
Code source
1 \begin{tikzpicture}
80
2 \begin{axis}[ybar]
60
3 \addplot coordinates {
40
20
0
0
0.5
1.5
Remarque
pgfplots permet de crer de vrais histogrammes (cf. option hist)
Confrence LATEX no 10
34 / 70
Autres graphiques
chelles (semi-)logarithmiques
Environnement axis semilogxaxis, semilogyaxis ou loglogaxis
102
Code source
1 \begin{tikzpicture}
2 \begin{semilogyaxis}
101
3 \addplot coordinates {
100
0
0.5
1.5
Remarque
chelles logarithmiques possibles : selon les abscisses
(semilogxaxis), les ordonnes (semilogyaxis), les deux
simultanment (loglogaxis)
Denis Bitouz (IUT GTE Dk & LMPA)
Confrence LATEX no 10
35 / 70
Graphiques 3D
Confrence LATEX no 10
36 / 70
Graphiques 3D
Syntaxe
Syntaxe
\addplot3 <donnes du graphique> ;
directe
partir dun fichier
partir dun fichier sous forme de tableau
Confrence LATEX no 10
37 / 70
Graphiques 3D
Reprsentation de surfaces
Donnes sous forme de fonctions
Code source
1 \begin{tikzpicture}
2 \begin{axis}
3 \addplot3[
4
5
6
7
8
9
10
surf,
domain=0:360,
samples=40
]
{sin(x)*sin(y)};
\end{axis}
\end{tikzpicture}
1
0
100
Confrence LATEX no 10
200
200
300
38 / 70
Graphiques 3D
Reprsentation de surfaces
Donnes sous forme de fonctions (avec barre de couleur : option colorbar)
Code source
0.5
1 \begin{tikzpicture}
2 \begin{axis}[colorbar]
1
0
3 \addplot3[
4
5
6
7
8
9
10
surf,
domain=0:360,
samples=40,
]
{sin(x)*sin(y)};
\end{axis}
\end{tikzpicture}
0
0.5
1
0
100
Confrence LATEX no 10
200
200
300
39 / 70
Graphiques 3D
Reprsentation de surfaces
Donnes sous forme de matrice (pour le maillage) : lignes vides
quivalent en coodonnes
0
1
2
0
0
0
0
0
0
0
1
2
1
1
1
0
0.6
0.7
0
1
2
2
2
2
0
0.7
0.8
Code source
\begin{tikzpicture}\begin{axis}
\addplot3[surf] file {3d.dat};
\end{axis}\end{tikzpicture}
0.5
0
0
Denis Bitouz (IUT GTE Dk & LMPA)
Confrence LATEX no 10
2
1
1
2 0
40 / 70
Graphiques 3D
Reprsentation de surfaces
Donnes sous forme de matrice : sans lignes vides (indiques par mesh/rows)
quivalent en coodonnes
0
1
2
0
1
2
0
1
2
0
0
0
1
1
1
2
2
2
0
0
0
0
0.6
0.7
0
0.7
0.8
Code source
\begin{tikzpicture}\begin{axis}
\addplot3[surf,mesh/rows=3]
file {3d-alt.dat};
\end{axis}\end{tikzpicture}
Confrence LATEX
0.5
0
0
no
10
2
1
1
2 0
41 / 70
Graphiques 3D
Reprsentation de courbes
Donnes pas sous forme de matrice (pas de maillage)
0
0
0
1
1
1
2
2
2
0
0
0
0
0.6
0.7
0
0.7
0.8
Code source
\begin{tikzpicture}\begin{axis}
\addplot3 file {3d-alt.dat};
\end{axis}\end{tikzpicture}
0.5
0
0
Confrence LATEX no 10
2
1
1
2 0
42 / 70
Divers
Confrence LATEX no 10
43 / 70
Divers
directe
Confrence LATEX no 10
44 / 70
Divers
Changement dchelle
Option scale=<facteur> ou styles prffinis
100
Code source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\newcommand{\myplot}{%
\addplot coordinates {
(0,1) (1,10) (2,100) }; }
%
\begin{tikzpicture}
\begin{axis}[scale=0.5]
\myplot
\end{axis}
\end{tikzpicture}
50
0
0
100
80
60
40
20
0
0
0.5
1.5
\begin{tikzpicture}
\begin{axis}[tiny]
\myplot
\end{axis}
\end{tikzpicture}
Confrence LATEX no 10
45 / 70
Divers
Code source
10
1 \begin{tikzpicture}
2 \begin{axis}
3 % Courbe
y = 10 x2
4 \addplot+[mark=none]
{10-x^2};
6 \end{axis}
7 \end{tikzpicture}
5
10
Confrence LATEX no 10
46 / 70
Divers
100
Code source
1 \begin{tikzpicture}
80
2 \begin{axis}
60
3 \addplot+[mark=none]
4
5
6
7
8
coordinates {
(0,1) (1,10) (2,100)
};
\end{axis}
\end{tikzpicture}
40
20
0
Confrence LATEX no 10
0.5
1.5
47 / 70
Divers
Courbes lisses
Option smooth
100
Code source
1 \begin{tikzpicture}
80
2 \begin{axis}
60
3 \addplot+[mark=none,smooth]
4
5
6
7
8
coordinates {
(0,1) (1,10) (2,100)
};
\end{axis}
\end{tikzpicture}
40
20
0
Confrence LATEX no 10
0.5
1.5
48 / 70
Divers
Axes classiques
Options axis x line et axis y line
15
Code source
10
1 \begin{tikzpicture}
2 \begin{axis}[
3 axis x line=center,
4 axis y line=center]
5 % Courbe y = x2 10
6 \addplot {x^2-10};
7 \end{axis}
10
8 \end{tikzpicture}
Confrence LATEX no 10
50 / 70
Divers
Graphiques multiples
Fonctions
Code source
10
1 \begin{tikzpicture}
2 \begin{axis}
3 % Courbe
= 10 x2
4 \addplot {10-x^2};
5 % Courbe y = x3 /20 10
10
6 \addplot
7 {x^3/20-10};
8 \end{axis}
9 \end{tikzpicture}
Confrence LATEX no 10
51 / 70
Divers
Graphiques multiples
Donnes exprimentales
100
Code source
1 \begin{tikzpicture}
80
2 \begin{axis}
60
3 \addplot coordinates {
4
5
6
7
8
9
10
40
20
0
Confrence LATEX no 10
0.5
1.5
52 / 70
Divers
Graphiques multiples
Donnes exprimentales en diagrammes en rectangles
Code source
1 \begin{tikzpicture}
2 \begin{axis}[ybar]
3 \addplot coordinates {
4
5
6
7
8
9
10
100
80
60
40
20
0
0
Confrence LATEX no 10
0.5
1.5
53 / 70
Divers
Code source
1 \begin{tikzpicture}
2 \begin{axis}[ybar,
3 nodes near coords,
80
60
40
5 ={vertical}]
20
6 \addplot coordinates {
100
100
10
1
0
Confrence LATEX no 10
0.5
1.5
54 / 70
Divers
Lgende
Commande \legend
1 \begin{tikzpicture}
0.8
2 \begin{axis}
0.6
3 \addplot coordinates {
4
5
6
7
8
Rponse no 2
Code source
0.4
0.2
0
Confrence LATEX no 10
0.5
1.5
55 / 70
Divers
1
2
3
4
5
6
7
8
9
10
11
\begin{tikzpicture}
\begin{axis}
\addplot coordinates {
(0,100) (1,10) (2,1)
};
\addplot coordinates {
(0,1) (1,0.1) (2,0.01)
};
\legend{Rponse \no 1,Rponse \no 3}
\end{axis}
\end{tikzpicture}
Rponse no 1
Rponse no 3
100
Code source
80
60
40
20
0
Confrence LATEX no 10
0.5
1.5
56 / 70
Divers
1
2
3
4
5
6
7
8
9
10
11
\begin{tikzpicture}
\begin{axis}[ybar]
\addplot coordinates {
(0,100) (1,10) (2,1)
};
\addplot coordinates {
(0,86) (1,17) (2,4)
};
\legend{Rponse \no 1,Rponse \no 4}
\end{axis}
\end{tikzpicture}
Rponse no 1
Rponse no 4
100
Code source
80
60
40
20
0
Confrence LATEX no 10
0.5
1.5
57 / 70
Divers
Label(s)
Options xlabel et ylabel
100
Code source
\begin{tikzpicture}
\begin{axis}[
xlabel=Temps,
ylabel=Rponse \no 1
]
\addplot coordinates {
(0,1) (1,10) (2,100)
};
\end{axis}
\end{tikzpicture}
80
Rponse no 1
1
2
3
4
5
6
7
8
9
10
60
40
20
0
0
Confrence LATEX no 10
0.5
1
Temps
1.5
58 / 70
Divers
Titre
Option title
Rponse no 1
Code source
1
2
3
4
5
6
7
8
9
\begin{tikzpicture}
\begin{axis}[
title=Rponse \no 1
]
\addplot coordinates {
(0,1) (1,10) (2,100)
};
\end{axis}
\end{tikzpicture}
100
80
60
40
20
0
0
0.5
1.5
Attention !
Il vaut bien mieux faire flotter le graphique : lgende possible
(\caption), listage possible (\listoffigures), emplacement optimis
Denis Bitouz (IUT GTE Dk & LMPA)
Confrence LATEX no 10
59 / 70
Divers
Titre
Mieux : image flottante
Code source
100
1 \begin{figure}[ht]
2
\centering
3
\begin{tikzpicture}
4
\begin{axis}
5
\addplot coordinates {
6
(0,1) (1,10) (2,100)
7
};
8
\end{axis}
9
\end{tikzpicture}
10
\caption{Rponse \no 1}
11
\label{fig:rep1}
12 \end{figure}
80
60
40
20
0
0
0.5
1.5
Figure 1 Rponse no 1
Confrence LATEX no 10
60 / 70
Configuration (semi-)globale
Confrence LATEX no 10
61 / 70
Configuration (semi-)globale
Configuration (semi-)globale
Un certains nombre de rglages peuvent tre effectus de faon
(semi-)globale au moyen de
Syntaxe
\pgfplotsset{<rglages>}
Confrence LATEX no 10
62 / 70
Configuration (semi-)globale
Rglage de compatibilit
Pour bnficier des fonctionnalits les plus rcentes, on effectuera
systmatiquement au moins le rglage 5 :
Code source
\pgfplotsset{compat = 1.12} % ou 1.11 ou 1.10 ou...
5. On remplacera 1.12 par 1.11, 1.10, etc. en cas de versions moins rcentes de
pgfplots
Denis Bitouz (IUT GTE Dk & LMPA)
Confrence LATEX no 10
63 / 70
Configuration (semi-)globale
0.4
0.2
0
2,960
Confrence LATEX no 10
2,980
3,000
3,020
64 / 70
Configuration (semi-)globale
0,4
0,2
0
2960
Confrence LATEX no 10
2980
3000
3020
65 / 70
Configuration (semi-)globale
Lgende(s)
Emplacement parfois convenable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Rponse no 1
Rponse no 4
100
Code source
80
60
40
\begin{tikzpicture}
\begin{axis}[ybar]
\addplot coordinates {
(0,100) (1,10) (2,1)
};
\addplot coordinates {
(0,86) (1,17) (2,4)
};
\legend{Rponse \no 1,Rponse \no 4}
\end{axis}
\end{tikzpicture}
20
0
Confrence LATEX no 10
0.5
1.5
66 / 70
Configuration (semi-)globale
Lgende(s)
Emplacement parfois gnant...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Rponse no 1
Rponse no 5
100
Code source
80
60
40
\begin{tikzpicture}
\begin{axis}[ybar]
\addplot coordinates {
(0,1) (1,10) (2,100)
};
\addplot coordinates {
(0,4) (1,17) (2,86)
};
\legend{Rponse \no 1,Rponse \no 5}
\end{axis}
\end{tikzpicture}
20
0
Confrence LATEX no 10
0.5
1.5
67 / 70
Configuration (semi-)globale
Lgende(s)
Emplacement parfois gnant... mais modifiable
Rponse no 1
Rponse no 5
Code source
1 \pgfplotsset{%
2
every axis legend/.append style = {
%
3
at = {(0.5,1.03)},%
4
anchor = south%
5
}
6 }
7 \begin{tikzpicture}
8 \begin{axis}[ybar]
9 \addplot coordinates {
10
(0,1) (1,10) (2,100)
11 };
12 \addplot coordinates {
13
(0,4) (1,17) (2,86)
14 };
15 \legend{Rponse \no 1,Rponse \no 5}
16 \end{axis}
17 \end{tikzpicture}
Denis Bitouz (IUT GTE Dk & LMPA)
100
80
60
40
20
0
Confrence LATEX no 10
0.5
1.5
68 / 70
Confrence LATEX no 10
69 / 70
Documents consulter
Bien dautres fonctionnalits et possibilits de personnalisation nont
pas pu tre abordes. On consultera
Comment faire de beaux graphiques avec Tikz et PGFPLOTS
sur le site Les fiches de Bbert (pour une vritable Publication
Assiste par Ordinateur)
un site rpertoriant un certain nombre de ralisations au moyen
du package pgfplots
la documentation du package : texdoc pgfplots
Confrence LATEX no 10
70 / 70