| 1 |
\chapter{Réaliser des graphiques} |
| 2 |
\backgroundimage{img/ch3} |
| 3 |
\thispagestyle{chapterpage} |
| 4 |
|
| 5 |
\newpage |
| 6 |
|
| 7 |
\section{Le package tikz-pgf} |
| 8 |
|
| 9 |
Il existe de nombreux paquets qui permettent de faire des graphiques. L'un des paquets les plus riches est \verb|pgf| (\url{https://www.ctan.org/pkg/pgf}) . Son manuel d'utilisation fait 1161 pages ! On peut trouver des exemples de ce qu'on peut faire sur le site \href{http://www.texample.net/tikz/examples/area/mathematics/}{texample.net}. |
| 10 |
|
| 11 |
Pour les besoins d'un manuel de maths, voici les graphiques que j'utilise de plus souvent: |
| 12 |
|
| 13 |
|
| 14 |
\section{Graphiques de fonctions} |
| 15 |
|
| 16 |
\subsection*{Fonction définie par une expression} |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
\begin{tcblisting}{colback=red!5!white,colframe=red!75!black,listing above text} |
| 21 |
\begin{tikzpicture}[scale=1,general] |
| 22 |
\window{-6}{8}{-30}{50} |
| 23 |
\begin{windowsratio} |
| 24 |
\draw[xstep=1,ystep=10,grid] (\Xmin,\Ymin) grid (\Xmax,\Ymax); |
| 25 |
\axeH;\axeV;\tickX;\tickY[10]; |
| 26 |
\node[below left] at (0,0) {0 }; |
| 27 |
\clip (\Xmin,\Ymin) rectangle (\Xmax,\Ymax); |
| 28 |
\def \f{-\x^3+5*(\x)^2+10*\x-15}; |
| 29 |
\draw[samples=100,domain=-6:8,courbe] |
| 30 |
plot(\x,{\f}); |
| 31 |
\end{windowsratio} |
| 32 |
\end{tikzpicture} |
| 33 |
\end{tcblisting} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
L'argument \verb|general| permet d'avoir le même style pour toutes les figures (par exemple la couleur et l'épaisseur du quadrillage). |
| 42 |
|
| 43 |
Les commandes \verb|\window|, \verb|\axeH|, \verb|\axeV|, \verb|\tickX| et \verb|\tickY| ainsi que l'environnement \verb|windowsratio| sont propres au package \verb|eshmathbook|. |
| 44 |
|
| 45 |
Les autres commandes appartiennent au package \verb|pgf|. |
| 46 |
|
| 47 |
|
| 48 |
\subsection*{Courbe qui passe par des points donnés} |
| 49 |
|
| 50 |
|
| 51 |
\begin{tcblisting}{colback=red!5!white,colframe=red!75!black,listing above text} |
| 52 |
\begin{tikzpicture}[scale=1,general] |
| 53 |
\window{-8}{5}{-5}{5} %\Xmin \Xmax \Ymin \Ymax |
| 54 |
\begin{windowsratio} |
| 55 |
\draw[xstep=1,ystep=1,grid] (\Xmin,\Ymin) grid (\Xmax,\Ymax); |
| 56 |
\axeH;\axeV;\tickX;\tickY; |
| 57 |
\node[below left] at (0,0) {0 }; |
| 58 |
\clip (\Xmin,\Ymin) rectangle (\Xmax,\Ymax); |
| 59 |
\draw[courbe] plot[smooth,tension=0.8] coordinates {(-7,2) (-6,-2) (-5,-3) (-4,-2) (-3,1)(-2,2) (-1,1) (0,-1) (1,-2) (2,-1) (4,3)}; |
| 60 |
\node[above left,color=blue] at (-2,2) {$y=f(x)$}; |
| 61 |
\draw[line width=1.2pt,courbe,color=blue] plot[only marks,mark=*,mark options={scale=2}] coordinates {(-7,2) (4,3)}; |
| 62 |
\end{windowsratio} |
| 63 |
\end{tikzpicture} |
| 64 |
\end{tcblisting} |
| 65 |
|
| 66 |
|
| 67 |
\section{Arbres pondérés} |
| 68 |
|
| 69 |
\subsection*{Arbre à deux fois deux branches} |
| 70 |
|
| 71 |
|
| 72 |
\begin{tcblisting}{colback=red!5!white,colframe=red!75!black,listing above text} |
| 73 |
\begin{tikzpicture}[level distance=20mm] % la longueur des branches |
| 74 |
\tikzstyle{level 1}=[sibling distance=20mm] % espace vertical |
| 75 |
\tikzstyle{level 2}=[sibling distance=10mm] |
| 76 |
\node {} [grow=right] |
| 77 |
child {node {$\overline{A}$} |
| 78 |
child {node {$\overline{B}$} |
| 79 |
edge from parent node[below]{$0,97$} |
| 80 |
} |
| 81 |
child {node {$B$} |
| 82 |
edge from parent node[above]{$0,03$} |
| 83 |
} |
| 84 |
edge from parent node[below]{$0,95$} |
| 85 |
} |
| 86 |
child {node {$A$} |
| 87 |
child {node {$\overline{B}$} |
| 88 |
edge from parent node[below]{$0,04$} |
| 89 |
} |
| 90 |
child {node {$B$} |
| 91 |
edge from parent node[above]{$0,96$} |
| 92 |
} |
| 93 |
edge from parent node[above]{$0,05$} |
| 94 |
}; |
| 95 |
\end{tikzpicture} |
| 96 |
\end{tcblisting} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
\subsection*{Arbre de trois fois deux branches} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
\begin{tcblisting}{colback=red!5!white,colframe=red!75!black,listing above text} |
| 105 |
\begin{tikzpicture}[level distance=20mm] |
| 106 |
\tikzstyle{level 1}=[sibling distance=20mm] |
| 107 |
\tikzstyle{level 2}=[sibling distance=10mm] |
| 108 |
\node {} [grow=right] |
| 109 |
child {node {$C$} |
| 110 |
child {node {$\overline{E}$} |
| 111 |
edge from parent node[below]{$0,97$} |
| 112 |
} |
| 113 |
child {node {$E$} |
| 114 |
edge from parent node[above]{$0,03$} |
| 115 |
} |
| 116 |
edge from parent node[below]{$0,95$} |
| 117 |
} |
| 118 |
child {node {$B$} |
| 119 |
child {node {$\overline{E}$} |
| 120 |
edge from parent node[below]{$0,97$} |
| 121 |
} |
| 122 |
child {node {$E$} |
| 123 |
edge from parent node[above]{$0,03$} |
| 124 |
} |
| 125 |
edge from parent node[below]{$0,95$} |
| 126 |
} |
| 127 |
child {node {$A$} |
| 128 |
child {node {$\overline{E}$} |
| 129 |
edge from parent node[below]{$0,04$} |
| 130 |
} |
| 131 |
child {node {$E$} |
| 132 |
edge from parent node[above]{$0,96$} |
| 133 |
} |
| 134 |
edge from parent node[above]{$0,05$} |
| 135 |
}; |
| 136 |
\end{tikzpicture} |
| 137 |
\end{tcblisting} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
\section{Géométrie dans l'espace} |
| 142 |
|
| 143 |
|
| 144 |
\begin{tcblisting}{colback=red!5!white,colframe=red!75!black,listing above text} |
| 145 |
\begin{tikzpicture}[x={(-1cm,-0.3cm)},z={(0cm,1cm)},y={(0.5cm,-0.5cm)}] |
| 146 |
|
| 147 |
\draw[->] (0,0,0)--(5,0,0) node[below] {$x$}; |
| 148 |
\draw[->] (0,0,0)--(0,5,0) node[right] {$y$}; |
| 149 |
\draw[->] (0,0,0)--(0,0,5) node[above] {$z$}; |
| 150 |
\foreach \x in {1,2,3,4} \draw (\x,0,0)--(\x,0.2,0); |
| 151 |
\foreach \x in {1,...,5} |
| 152 |
{\draw[color=blue] (0,\x,0)--(0,\x,5); |
| 153 |
\draw[color=blue] (0,0,\x)--(0,5,\x);} |
| 154 |
\node[above left] at (1,0,0) {$1$}; |
| 155 |
\node[below] at (0,1,0) {$1$}; |
| 156 |
\node[left] at (0,0,1) {$1$}; |
| 157 |
\node[below] at (0,0,0) {0}; |
| 158 |
|
| 159 |
\draw[dashed] (5,1,4)--(-3,5,0); |
| 160 |
\draw[color=green!50!black] plot[mark=*] coordinates {(5,1,4)} node[right]{$A$}; |
| 161 |
\draw[color=green!50!black] plot[mark=*] coordinates {(3,2,3)} node[right]{$B$}; |
| 162 |
\draw[color=green!50!black] plot[mark=*] coordinates {(-3,5,0)} node[right]{$C$}; |
| 163 |
|
| 164 |
\end{tikzpicture} |
| 165 |
\end{tcblisting} |