Debian Codegraph @

texmf-dist/doc/latex/tzplot/tzplot-doc-B-v2.2.tex

raw
1 %!TEX root = tzplot-doc.tex
2 %\begin{document}
3
4 %%%==================================
5 \part{Getting Started}
6 %%%==================================
7 \label{p:gettingstarted}
8
9 %%==================================
10 \chapter{An Intuitive Introduction I: Basics}
11 \label{ci:introI}
12
13 All drawing macros provided in this package work within |tikzpicture| environment, just like any other \Tikz\ commands.
14
15 %%------------------------------------------------------------
16 \section{Lines: Basics: \protect\cmd{\tzline(0,0)(3,1)}}
17 \label{si:lines}
18
19 To draw a line from $(0,0)$ to $(3,1)$, just do |\tzline(0,0)(3,1)|.
20
21 \begin{tzcode}{.3}
22 % \tzline
23 \begin{tikzpicture}
24 \tzhelplines(4,2)
25 \tzline(0,0)(3,1)
26 \end{tikzpicture}
27 \end{tzcode}
28
29 You can use \Tikz\ options to change the style of a line.
30
31 \begin{tzcode}{.3}
32 % \tzline: change line style
33 \begin{tikzpicture}
34 \tzhelplines(4,3)
35 \tzline(0,0)(3,1)
36 \tzline[dashed](0,1)(3,2)
37 \tzline[->,blue,thick](0,3)(4,1)
38 \end{tikzpicture}
39 \end{tzcode}
40
41 \begin{tztikz}
42 \tzline[dashed](0,1)(3,2) % works like:
43 \draw [dashed] (0,1) -- (3,2);
44 \end{tztikz}
45
46
47 %%------------------------------------------------------------
48 \section{Dots: Basics}
49 \label{si:dots}
50
51 \subsection{A circle dot: \protect\cmd{\tzcdot(0,0)}}
52 \label{ssi:tzcdot}
53
54 \icmd{\tzcdot}|(0,0)| prints a `circle dot' \tikz \tzcdot(0,0);, with the \xem{radius} |1.2pt| by default, at the point |(0,0)|. The starred version \icmd{\tzcdot*} prints a filled dot \tikz \tzcdot*(0,0);.
55
56 \begin{tzcode}{.3}
57 % \tzcdot: circle dot
58 \begin{tikzpicture}
59 \tzhelplines(4,3)
60 \tzcdot(0,0)
61 \tzcdot*(3,1)
62 \tzcdot [red] (0,1)(3pt) % radius=3pt
63 \tzcdot*[green](3,2)(3pt) % radius=3pt
64 \end{tikzpicture}
65 \end{tzcode}
66
67 You can change of the size of a dot by specifying the \xem{radius} of the circle, like, for example, |\tzcdot(0,0)(3pt)|.
68
69 \begin{tztikz}
70 \tzcdot*[green](3,2)(3pt) % is an abbreviation for:
71 \draw [fill,green] (3,2) circle (3pt);
72 \end{tztikz}
73
74 \begin{tzcode}{.3}
75 % \tzcdot
76 \begin{tikzpicture}
77 \tzhelplines(4,3)
78 \tzcdot(0,0) \tzcdot*(3,1)
79 \tzcdot[red](0,1)(2mm) % radius=2mm
80 \tzcdot*[green](3,2)(3pt) % radius=3pt
81 \tzline(0,0)(3,1)
82 \tzline(0,1)(3,2)
83 \end{tikzpicture}
84 \end{tzcode}
85
86
87 \subsection{A circle node dot: \protect\cmd{\tzdot(0,0)}}
88 \label{ssi:tzdot}
89
90 \icmd{\tzdot} draws a `circle node dot' at a specified coordinate.
91 The starred version \icmd{\tzdot*} prints a filled dot. The default size (\xem{diameter} or |minimum size|) is |2.4pt|.
92
93 \begin{tzcode}{.3}
94 % \tzdot: node dot
95 \begin{tikzpicture}
96 \tzhelplines(4,3)
97 \tzdot(0,0) \tzdot*(3,1)
98 \tzdot[red](0,1)(4mm) % minimum size=4mm
99 \tzdot*[green](3,2)(6pt) % minimum size=6pt
100 \tzline(0,0)(3,1)
101 \tzline(0,1)(3,2)
102 \end{tikzpicture}
103 \end{tzcode}
104
105
106 The size (\xem{diameter} or |minimum size|) of a node dot can be changed by the second (or the last) parenthesis option, like |(6pt)|.
107
108 \begin{tzcode}{.3}
109 % \tzcdot
110 \begin{tikzpicture}
111 \tzhelplines(4,3)
112 \tzdot(0,0)(5pt) \tzdot*(3,1)
113 \tzdot[red](0,1)(4mm) \tzdot*[green](3,2)(6pt)
114 \tzline(0,0)(3,1)
115 \tzline(0,1)(3,2)
116 \end{tikzpicture}
117 \end{tzcode}
118
119 \begin{tztikz}
120 \tzdot[green](0,0)(6pt) % works like:
121 \draw [green] (0,0) node [tzdot,minimum size=6pt] {};
122 % tzdot style is predefined
123 \end{tztikz}
124
125
126 \subsection{Difference between \protect\cmd{\tzcdot} and \protect\cmd{\tzdot}}
127 \label{ssi:difference}
128
129 A `circle dot' drawn by |\tzcdot| is affected by |xscale| or |yscale| in \Tikz, but a `circle node dot' drawn by |\tzdot| is not.
130 Note also that |\tzcdot| controls the \xem{radius} of a circle dot (following \Tikz\ practice), while |\tzdot| controls the \xem{diameter} of a circle node dot.
131
132 \begin{tzcode}{.3}
133 % \tzdot: size not changed by scaling
134 \begin{tikzpicture}[xscale=.5,yscale=1.1] %%
135 \tzhelplines(4,3)
136 \tzdot(0,0) \tzdot*(3,1)
137 \tzdot[red](0,1)(4mm) \tzdot*[green](3,2)(6pt)
138 \tzline(0,0)(3,1)
139 \tzline(0,1)(3,2)
140 \end{tikzpicture}
141 \end{tzcode}
142
143
144 \remark
145 The circle dots drawn by |\tzcdot| are affected by \Tikz\ |scale| factors. It gets bigger or smaller by |scale|.
146 Let us see what happens to circle dots, especially when |xscale| and |yscale| are not symmetric.
147
148 \begin{tzcode}{.3}
149 % \tzcdot: distorted
150 \begin{tikzpicture}[xscale=.5,yscale=1.1] %%
151 \tzhelplines(4,3)
152 \tzcdot(0,0) \tzcdot*(3,1)
153 \tzcdot[red](0,1)(2mm) \tzcdot*[green](3,2)(3pt)
154 \tzline(0,0)(3,1)
155 \tzline(0,1)(3,2)
156 \end{tikzpicture}
157 \end{tzcode}
158
159
160
161
162 %%------------------------------------------------------------
163 \section{Coordinates: Basics: \protect\cmd{\tzcoor(0,0)(A)}}
164 \label{si:coordinates}
165
166 To define a coordinate, use \icmd{\tzcoor} with a coordinate followed by its name in parentheses.
167
168 \begin{tztikz}
169 \tzcoor(0,0)(A) % works like:
170 \path (0,0) coordinate (A);
171 % or
172 \coordinate (A) at (0,0);
173 \end{tztikz}
174
175 \begin{tzcode}{.3}
176 \begin{tikzpicture}
177 \tzhelplines(4,3)
178 \tzcoor(0,0)(A) \tzcoor(60:3cm)(B)
179 \tzline[->](A)(B)
180 \tzdot(A)(5pt)
181 \tzcoor(0,1)(C) \tzcoor(4,2)(D)
182 \tzline[dashed](C)(D)
183 \end{tikzpicture}
184 \end{tzcode}
185
186 The starred version \icmd{\tzcoor*} prints a filled node dot at a specified coordinate.
187
188 \begin{tzcode}{.3}
189 \begin{tikzpicture}
190 \tzhelplines(4,3)
191 \tzcoor(0,0)(A) \tzcoor(60:3cm)(B)
192 \tzline[->](A)(B)
193 \tzdot(A)(5pt)
194 \tzcoor*(0,1)(C) \tzcoor*[fill=none](4,2)(D)
195 \tzline[dashed](C)(D)
196 \end{tikzpicture}
197 \end{tzcode}
198
199 %%------------------------------------------------------------
200 \section{Curves: Basics}
201 \label{si:curves}
202
203 \subsection{\protect\cmd{\tzto(0,0)(4,2)}}
204 \label{ssi:tzto}
205
206 \icmd{\tzto} connects two points with a line or a curve using the |to| operation of \Tikz.
207
208 \begin{tzcode}{.3}
209 \begin{tikzpicture}
210 \tzhelplines(4,3)
211 \tzto(0,0)(4,2)
212 \tzto[bend right,dashed](0,1)(3,2)
213 \tzto[out=90,in=-90,->,blue](0,2)(4,1)
214 \end{tikzpicture}
215 \end{tzcode}
216
217 \begin{tztikz}
218 \tzto[bend right](0,1)(3,2) % works like:
219 \draw [bend right] (0,1) to (3,2);
220 \end{tztikz}
221
222 \subsection{\protect\cmd{\tzbezier}}
223 \label{ssi:tzbezier}
224
225 \icmd{\tzbezier} draws a B\'{e}zier curve with \xem{one or two} control points from the first coordinate to the last coordinate.
226 The style |tzshowcontrols| predefined in the package reveals the control point(s).
227
228 \begin{tzcode}{.3}
229 \begin{tikzpicture}
230 \tzhelplines(4,3)
231 \tzbezier[blue,thick](0,0)(2,0)(4,2)
232 \tzbezier[->,tzshowcontrols](0,2)(1,3)(3,0)(4,1)
233 \end{tikzpicture}
234 \end{tzcode}
235
236 \begin{tztikz}
237 \tzbezier[blue](0,0)(2,0)(4,2) % works like:
238 \draw [blue] (0,0) .. controls (2,0) .. (4,2);
239 \tzbezier(0,2)(1,3)(3,0)(4,1) % works like:
240 \draw (0,2) .. controls (1,3) and (3,0) .. (4,1);
241 \end{tztikz}
242
243 \subsection{\protect\cmd{\tzparabola}}
244 \label{ssi:tzparabola}
245
246 \icmd{\tzparabola} draws a parabola controlled by several options of \Tikz's |parabola| operation.
247 The macro \icmd{\tzparabola} accepts \xem{two or three} coordinate arguments to draw a parabola and the parabola bends at the second coordinate if it exists.
248
249 \begin{tztikz}
250 \tzparabola(0,0)(2,4) % works like:
251 \draw (0,0) parabola (2,4);
252 \tzparabola(2,0)(3,3)(4,1) % works like:
253 \draw (2,0) parabola bend (3,3) (4,1);
254 \end{tztikz}
255
256
257 \begin{tzcode}{.3}
258 \begin{tikzpicture}
259 \tzhelplines(4,4)
260 \tzparabola(0,0)(2,4)
261 \tzparabola[bend at end,dashed](0,0)(2,4)
262 \tzparabola(2,0)(3,3)(4,1)
263 \tzparabola[bend pos=.33,dashed](1,0)(4,4)
264 \end{tikzpicture}
265 \end{tzcode}
266
267
268
269
270
271 %%------------------------------------------------------------
272 \section{Adding text: Nodes and placement}
273 \label{si:addingtext}
274
275 \subsection{\protect\cmd{\tznode(3,1)\{text\}[right]}}
276 \label{ssi:tznode}
277
278 With \icmd{\tznode}|(<coor>){<text>}[<node opt>]|, you can put some text at a specified position.
279 The starred version \icmd{\tznode*} draws the node perimeter, which is a |rectangle| by default.
280
281 \begin{tzcode}{.3}
282 \begin{tikzpicture}
283 \tzhelplines(4,3)
284 \tznode(0,0){A}
285 \tznode*(1,1){text}
286 \tzdot*(2,2)
287 \tznode(2,2){Text}[above right,blue]
288 \end{tikzpicture}
289 \end{tzcode}
290
291
292 \begin{tztikz}
293 \tznode(0,0){A} % works like:
294 \node at (0,0) {A};
295 \tznode(2,2){Text}[above right,blue] % works like:
296 \draw (2,2) node [above right,blue] {Text};
297 \end{tztikz}
298
299 \subsection{Review: Main nodes and label nodes in \Tikz}
300 \label{ssi:mainnodes}
301
302 In \Tikz, there are two kinds of nodes: main nodes and label nodes.
303
304 When a \iisw{main node} with text in it is placed at a specific point, its \iisw{label node} with a label in it is optionally placed in the \xem{direction} of a designated \xem{angle} relative to the main node.
305
306 \begin{tzcode}{.3}
307 \begin{tikzpicture}
308 \tzhelplines(4,3)
309 \tznode*(2,1){main node}
310 [scale=2,label={[draw,red]90:label node}]
311 \tznode*(3,3){A}[label={above:a},label={0:r}]
312 \end{tikzpicture}
313 \end{tzcode}
314
315 Instead of angles, you can use the corresponding placement words. In \Tikz, for example, |above| is replaced by |90| degree, |right| by |0| degree, |below left| by |-135| degree, and the like. Note that the angle expression \xem{cannot} be used for placing main nodes.
316
317 \xmedskip1
318 \remark
319 \begin{itemize}
320 \item
321 In this package, macros related to `dots' or `coordinates' (like |\tzcdot|, |tzdot|, and |\tzcoor|) can optionally have `label nodes,' while macros related to `lines' and `curves' (like |\tzline|, |\tzto|, |\tzbezier| and |\tzparabola|) optionally have `main nodes' or `text nodes.'
322 \item
323 There is one exception: |\tzshoworigin|. |\tzshoworigin| can have a label, but its location is controlled by positional words such as |below left| but not by |<angle>|.
324 (See Section \ref{s:tzshoworigin} on page \pageref{s:tzshoworigin} for more details.)
325 \end{itemize}
326
327 \subsection{Abbreviations of \Tikz\ basic placement option styles: \texttt{a}, \texttt{r}, \texttt{ar}, \texttt{bl}, etc.}
328 \label{ssi:abbreviations}
329
330 You can use \isw{abbreviations} (or aliases) |a| for |above|, |c| for |centered|, |r| for |right|, |bl| for |below left|, and so on to place \iisw{main node}\xem{s}.
331 (Again, you \xem{cannot} use angels to place main nodes.)
332
333 \begin{tzcode}{.3}
334 \begin{tikzpicture}[font=\ttfamily,text=blue]
335 \tzhelplines[thick](2,2)
336 \tznode(1,1){centered}[draw] % default: centered
337 \tznode(1,2){a} [a] \tznode(1,0){b} [b]
338 \tznode(0,1){l} [l] \tznode(2,1){r} [r]
339 \tznode(0,2){al}[al] \tznode(2,2){ar}[ar]
340 \tznode(0,0){bl}[bl] \tznode(2,0){br}[br]
341 \end{tikzpicture}
342 \end{tzcode}
343
344 %%------------------------------------------------------------
345 \section{Labeling dots and coordinates}
346 \label{si:labelingdots}
347
348 \subsection{\protect\cmd{\tzdot}, \protect\cmd{\tzcdot}}
349 \label{ssi:labeling:tzdot}
350
351 To add a label to a dot generated by |\tzdot| or |\tzcdot|, you should specify, \xem{right after a coordinate}, |{<label>}| followed by |[<angle>]| (|90| degree or |above| by default in \Tikz).
352
353 \textsc{Remember} that the order of the arguments is |(<coor>){<label>}[<angle>]|.
354 To change the size of a dot, you need to specify the last option |(<dimension>)| after all the other arguments.
355
356 \begin{tzcode}{.3}
357 \begin{tikzpicture}
358 \tzhelplines(4,3)
359 \tzdot*(1,1){A} % default: 90 or above
360 \tzdot(2,1){B}[0](4pt)
361 \tzcdot*(1,2){C}[180](2pt)
362 \tzcdot(3,2){D}[45]
363 \tzdot*(4,0){E}[[red,draw]180](4pt)
364 \end{tikzpicture}
365 \end{tzcode}
366
367 \begin{tztikz}
368 \tzcdot*(1,2){C}[180](2pt) % works like:
369 \draw[fill] (1,2) circle (2pt) node [label={180:C}] {};
370 \end{tztikz}
371
372 \subsection{\protect\cmd{\tzcoor}}
373 \label{ssi:tzcoor}
374
375 \icmd{\tzcoor} can add a label to a coordinate. Just append the optional arguments |{<label>}| and |[<angle>]| after the two mandatory parenthesis arguments.
376
377 \remark
378 \textsc{Remember} the order of arguments is |(<coor>)(<name>){<label>}[<angle>]|.
379
380 \begin{tzdef}
381 % syntax: simplified
382 \tzcoor(<coor>)(<coor name>){<label>}[[<label opt>]<angle>]
383 % defaults
384 (<m>)(<m>){}[]
385 % <m> means `mandatory'
386 \end{tzdef}
387
388 You can see the full syntax of |\tzcoor| in Section \ref{s:tzcoor} on page \pageref{s:tzcoor}.
389
390 \begin{tzcode}{.3}
391 \begin{tikzpicture}
392 \tzhelplines(4,2)
393 \tzcoor(1,1)(A){A} % default: 90 or above
394 \tzcoor(2,1)(B){B}[[red]0]
395 \end{tikzpicture}
396 \end{tzcode}
397
398 \begin{tztikz}
399 \tzcoor(1,1)(B){B}[0] % works like:
400 \draw (1,1) coordinate (B) node [label={0:B}] {};
401 \tzcoor(1,1)(B){B}[[red]0] % works like:
402 \draw (1,1) coordinate (B) node [label={[red]0:B}] {};
403 \end{tztikz}
404
405 \subsection{\protect\cmd{\tzcoor*}}
406 \label{ssi:tzcoor*}
407
408 The starred version \icmd{\tzcoor*} designates a coordinate and prints a node dot with a label around the designated point like |\tzdot*| does.
409
410 \begin{tzdef}
411 % syntax: simflified
412 \tzcoor*[<dot opt>](<coor>)(<coor name>){<label>}[[<label opt>]<angle>](<dot size>)
413 \end{tzdef}
414
415 \begin{tzcode}{.3}
416 \begin{tikzpicture}
417 \tzhelplines(4,3)
418 \tzcoor(1,1)(A){A} % default: 90 or above
419 \tzcoor(2,1)(B){B}[0]
420 \tzcoor*(1,2)(C){C}[180](4pt)
421 \tzcoor*[fill=none](3,2)(D){D}[45]
422 \tzcoor*(4,0)(E){E}[[red,draw]180](4pt)
423 \end{tikzpicture}
424 \end{tzcode}
425
426 \begin{tztikz}
427 \tzcoor*(1,2)(C){C}[180](4pt) % works as follows:
428 \tzcoor(1,2)(C)
429 \tzdot*(C){C}[180](4pt)
430 \end{tztikz}
431
432 %%------------------------------------------------------------
433 \section{Adding text next to lines or curves}
434 \label{si:texttolines}
435
436 \subsection{\protect\cmd{\tzline}}
437 \label{ssi:texttotzline}
438
439 \icmd{\tzline} accepts two mandatory coordinates.
440 To add text to a line segment, just specify the optional arguments |{<text>}| and |[<node opt>]| \xem{in-between} the two coordinates. The |[<node opt>]| is |[above,midway]|, by default.
441
442 \begin{tzcode}{.3}
443 \begin{tikzpicture}
444 \tzhelplines(4,3)
445 \tzline(0,0){route A}(3,0)
446 \tzline[dashed](1,1){route B}(4,1)
447 \tzline[blue]
448 (0,3) {plan C} [below,near end] (3,3)
449 \end{tikzpicture}
450 \end{tzcode}
451
452 The optional argument |{<text>}| \xem{following the second coordinate} can also be used as a name of the graph. By default, it is placed at the second coordinate.
453
454 \begin{tzcode}{.3}
455 \begin{tikzpicture}
456 \tzhelplines(4,3)
457 \tzline(0,3)(4,0){demand}
458 \tzline(0,0)(3,3){supply}[r]
459 \end{tikzpicture}
460 \end{tzcode}
461
462
463 \subsection{\protect\cmd{\tzto}}
464 \label{ssi:texttotzto}
465
466 To add text to a line or a curve drawn by \icmd{\tzto}, just specify the optional arguments |{<text>}| and |[<node opt>]| \xem{in-between} the two coordinates. By default, the |[<node opt>]| is |[above,midway]|.
467
468 \begin{tzcode}{.3}
469 \begin{tikzpicture}
470 \tzhelplines(4,3)
471 \tzto(0,0){route A}(3,0)
472 \tzto[dashed,bend left](1,1){route B}(4,1)
473 \tzto[blue,bend right]
474 (0,3) {plan C} [below,near end] (3,3)
475 \end{tikzpicture}
476 \end{tzcode}
477
478 \begin{tztikz}
479 \tzto(0,0){route A}(3,0) % works like:
480 \draw (0,3) to node [above] {route A} (3,0);
481 \end{tztikz}
482
483 The optional argument |{<text>}| \xem{following the second coordinate} can also be used as a name of the graph. By default, it is placed at the second coordinate.
484
485 \begin{tzcode}{.3}
486 \begin{tikzpicture}
487 \tzhelplines(4,3)
488 \tzto[bend right=15](0,3)(4,0){demand}
489 \tzto[bend right=10](0,0)(3,3){supply}[r]
490 \end{tikzpicture}
491 \end{tzcode}
492
493
494
495 \subsection{\protect\cmd{\tzbezier}}
496 \label{ssi:texttotzbezier}
497
498 \icmd{\tzbezier} accepts three or four coordinates as arguments.
499 You can add text to the curve drawn by |\tzbezier| using the optional arguments |{<text>}| and |[<node opt>]| after the last coordinate.
500
501 \begin{tzcode}{.3}
502 \begin{tikzpicture}
503 \tzhelplines(4,3)
504 \tzbezier(0,2)(1,3)(3,0)(4,1){curve}[r]
505 \tzbezier[red,yshift=-5mm]
506 (0,2)(1,3)(3,0)(4,1){curve}[midway]
507 \tzbezier[green,text=blue,yshift=-10mm]
508 (0,2)(1,3)(3,0)(4,1){curve}[b,near end]
509 \end{tikzpicture}
510 \end{tzcode}
511
512
513 \subsection{\protect\cmd{\tzparabola}}
514 \label{ssi:texttotzparabola}
515
516 You can add text to a parabola drawn by |\tzparabola| using the optional arguments |{<text>}| and |[<node opt>]| \xem{following the last coordinate}.
517 The text is placed at (by default) or around the last coordinate according to |[<node opt>]|.
518
519
520 \begin{tzcode}{.3}
521 \begin{tikzpicture}
522 \tzhelplines(4,3)
523 \tzparabola(0,2)(1,.5)(3,2){$AC$}[r]
524 \tzparabola[bend at end,blue](0,0)(4,3){$u(x)$}[r,red]
525 \end{tikzpicture}
526 \end{tzcode}
527
528
529 %%==================================
530 \chapter{An Intuitive Introduction II: Repetition of Coordinates}
531 \label{ci:introII}
532
533 %%------------------------------------------------------------
534 \section{Linking many coordinates: Semicolon versions}
535 \label{si:liknmanycoordinates}
536
537 \subsection{\protect\cmd{\tzlines}: Connected line segments}
538 \label{ssi:tzlines}
539
540 \icmd{\tzlines} connects with line segments an arbitrary number of coordinates. The coordinate iteration must end with a semicolon |;|.
541 Here, the \xem{semicolon} `|;|' indicates \xem{the end of repetition} of coordinates.
542 Let us call this kind of macro a \iisw{semicolon version} macro.
543
544 \remark: Without the semicolon |;|, an error occurs with the the \iisw{error message}:
545 \begin{verbatim}
546 ! Package tzplot Error: You may have forgotten a semicolon here or above!
547 \end{verbatim}
548
549 \begin{tzdef}
550 % syntax: minimal
551 \tzlines[<opt>](<coor>)(<coor>)..repeated..(<coor>);
552 % syntax: simplified
553 \tzlines[<opt>]"<path name>"
554 (<coor>){<label>}[<angle>]..repeated..(<coor>){<label>}[<angle>];
555 % defaults
556 []""(<m>){}[]..repeated..(){}[];
557 % <m> means mandatory
558 \end{tzdef}
559
560
561 \begin{tzcode}{.3}
562 \begin{tikzpicture}
563 \tzhelplines(4,3)
564 \tzlines(0,0)(1,2)(3,0)
565 (4,1)(2,2)(3,3)
566 (0,3)(0,1)(4,2) ; % semicolon
567 \end{tikzpicture}
568 \end{tzcode}
569
570 With the optional argument |{<text>}| followed by |[<node opt>]| \xem{in-between two coordinates}, you can print |{<text>}| at or around the middle point of the corresponding line segment in accordance with |[<node opt>]| (by default |[midway]|).
571
572 \begin{tzcode}{.3}
573 \begin{tikzpicture}
574 \tzhelplines(4,3)
575 \tzlines[dashed,->](0,0){up}[l]
576 (1,2){down}[r]
577 (3,0){up}[r]
578 (4,1) ; % semicolon
579 \end{tikzpicture}
580 \end{tzcode}
581
582 The optional argument |{<text>}| \xem{following the last coordinate} can be used as a name of the whole connected line segments. The |{<text>}| is placed at (by default) or around the last coordinate according to |[<node opt>]|.
583
584 \begin{tzcode}{.3}
585 \begin{tikzpicture}[sloped,auto]
586 \tzhelplines(4,3)
587 \tzlines[dashed,->](0,0){up}
588 (1,2){down}
589 (3,0){up}
590 (4,1){Weight}[r,blue] ; % semicolon
591 \end{tikzpicture}
592 \end{tzcode}
593
594 \textsc{Remember} the repeating pattern is the triple |(<coor>){<text>}[<node opt>]| in that order.
595 DO NOT FORGET to indicate when the repetition ends by typing a semicolon. So it will look like |(){}[]..repeated..(){}[];|.
596
597 \subsection{\protect\cmd{\tzpolygon}, \protect\cmd{\tzpolygon*}: Closed paths}
598 \label{ssi:tzpolygon}
599
600 \icmd{\tzpolygon} draws closed line segments. |\tzpolygon| is also one of semicolon versions, meaning that it has to end with a semicolon |;|.
601 In fact, |\tzpolygon| is a closed version of |\tzlines|.
602
603 The starred version |\tzpolygon*| does the same thing as |\tzpolygon| except for one thing.
604 |\tzpolygon*|, by default, fills the interior of the polygon with |black!50| with |fill opacity=.3| but with |text opacity=1|. (Changing the |fill opacity| is not an issue in this introduction. See Section \ref{ss:tzpolygon} on page \pageref{ss:tzpolygon} for more details.)
605
606 \begin{tzcode}{.3}
607 \begin{tikzpicture}
608 \tzhelplines(4,3)
609 \tzpolygon(1,3)(0,2)(2,0)(3,1)(4,2)(2,3); % semicolon
610 \end{tikzpicture}
611 \end{tzcode}
612
613 The optional arguments |{<text>}| and |[<node opt>]| \xem{in-between} two coordinates prints |<text>| according to |[<node opt>]| (by default |[midway]|) around the middle point of the corresponding line segment.
614
615 \begin{tzcode}{.3}
616 \begin{tikzpicture}
617 \tzhelplines(4,3)
618 \tzpolygon*[green,thick](1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
619 \tzpolygon[dashed]
620 (0,0){up}[l] (1,2){down}[r] (3,0){up}[r] (4,1);
621 \end{tikzpicture}
622 \end{tzcode}
623
624 The options |{<text>}| and |[<node opt>]| following the last coordinate can be used as a name of the connected line segments.
625
626 The entire repetition will look like |(<coor>){<text>}[<node opt>] ..repeated.. (){}[];|.
627 DO NOT FORGET to indicate when the repetition ends by typing a semicolon.
628
629 \begin{tzcode}{.3}
630 \begin{tikzpicture}[sloped,auto]
631 \tzhelplines(4,3)
632 \tzpolygon[dashed]
633 (0,0){up} (1,2){down} (3,0){up} (4,1){Weight}[r] ;
634 \end{tikzpicture}
635 \end{tzcode}
636
637 \subsection{\protect\cmd{\tzpath*}: Filling area}
638 \label{ssi:tzpath}
639
640 \icmd{\tzpath} accepts an arbitrary number of coordinates to form a path, like |\tzlines| does, but the path is invisible. This is a \xem{semicolon version} macro, so the coordinate iteration must be ended by a semicolon |;|.
641 With |[draw]| option you can visualize the invisible path.
642
643 \begin{tzcode}{.3}
644 \begin{tikzpicture}
645 \tzhelplines(4,3)
646 \tzpath[draw](1,3)(0,2)(2,0)
647 (3,1)(4,2)(2,3); % semicolon
648 \end{tikzpicture}
649 \end{tzcode}
650
651 You can fill the interior of a path formed by |\tzpath| (after being closed) with color or pattern, in usual \Tikz\ way.
652
653 \begin{tzcode}{.3}
654 \begin{tikzpicture}
655 \tzhelplines(4,3)
656 \tzline[blue](0,3)(4,0)
657 \tzpath[pattern=crosshatch]
658 (1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
659 \tzpath[pattern=bricks,preaction={fill=brown}]
660 (0,0) (1,2) (3,0) (4,1);
661 \end{tikzpicture}
662 \end{tzcode}
663
664 \begin{tzcode}{.3}
665 \begin{tikzpicture}
666 \tzhelplines(4,3)
667 \tzline[blue](0,3)(4,0)
668 \tzpath[fill,green]
669 (1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
670 \tzpath[fill]
671 (0,0) (1,2) (3,0) (4,1);
672 \end{tikzpicture}
673 \end{tzcode}
674
675
676
677 The starred version \icmd{\tzpath*} takes the default options |fill=black!50|, |fill opacity=.3|, and |text opacity=1| to fill the area.
678
679 \begin{tzdef}
680 % syntax: simplified
681 \tzpath*[<opt>](<coor>){<label>}[<angle>]..repeated..(<coor>){<label>}[<angle>];
682 % defaults
683 *[fill=black!50,fill opacity=.3,text opacity=1](<m>){}[]..repeated..(){}[];
684 % <m> means mandatory
685 \end{tzdef}
686
687 The macros |\tzpath| and |\tzpath*| are much more flexible. See Section \ref{s:tzpath} on page \pageref{s:tzpath} for more details.
688
689
690 \begin{tzcode}{.3}
691 \begin{tikzpicture}
692 \tzhelplines(4,3)
693 \tzline[blue](0,3)(4,0)
694 \tzpath*[green](1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
695 \tzpath*(0,0) (1,2) (3,0) (4,1);
696 \end{tikzpicture}
697 \end{tzcode}
698
699 How to change the |fill opacity| with |\tzpath*| is not discussed in this introduction, but one example is given below. (See Section \ref{s:tzpath*} on page \pageref{s:tzpath*} for more details.)
700
701 \begin{tzcode}{.3}
702 \begin{tikzpicture}
703 \tzhelplines(4,3)
704 \tzline[blue](0,3)(4,0)
705 \tzpath*[green](1,3)(0,2)(2,0)(3,1)(4,2)(2,3);{1} %%
706 \tzpath*(0,0) (1,2) (3,0) (4,1);{.7} %%
707 \end{tikzpicture}
708 \end{tzcode}
709
710
711
712 %%------------------------------------------------------------
713 \section{Many dots: Semicolon versions}
714 \label{si:manydots}
715
716 \subsection{\protect\cmd{\tzcdots(*)}}
717 \label{ssi:tzcdots}
718
719 \icmd{\tzcdots} accepts an arbitrary number of coordinates to print circle dots, but the coordinate repetition must be ended by |;| (semicolon version).
720 \icmd{\tzcdots*} prints filled circle dots.
721
722 \begin{tzcode}{.3}
723 \begin{tikzpicture}
724 \tzhelplines(4,3)
725 \tzcdots(0,0)(1,1)(2,1)(3,2)(4,3);
726 \tzcdots*[red](0,3)(1,3)(2,3)(3,3)(4,2); % semicolon
727 \end{tikzpicture}
728 \end{tzcode}
729
730 Each coordinate can be labeled by specifying the optional argument |{<label>}| followed by |[<angle>]|. You can also change the size (\xem{radius}) of the dots by specifying the \xem{last} parenthesis option |(<dot radius>)| \xem{after} the semicolon.
731
732 \begin{tzcode}{.3}
733 \begin{tikzpicture}
734 \tzhelplines(4,3)
735 \tzcdots(0,0)(1,1){B}(2,1)(3,2){D}[-90](4,3);(5pt)
736 \tzcdots*[fill=red](0,3){A}
737 (1,3){B}
738 (2,3){C}[-90]
739 (3,3)
740 (4,2){E}[[blue]0];(3pt) % radius
741 \end{tikzpicture}
742 \end{tzcode}
743
744
745
746 \subsection{\protect\cmd{\tzdots(*)}}
747 \label{ssi:tzdots}
748
749 \icmd{\tzdots} accepts an arbitrary number of coordinates to print circle node dots, but the repetition must be ended by |;| (semicolon version).
750 \icmd{\tzdots*} prints filled circle node dots.
751
752 \begin{tzdef}
753 % syntax: minimum
754 \tzdots*(<coor>)(<coor>)..repeated..(<coor>);
755 % syntax: simplified
756 \tzdots*[<opt>](<coor>){<label>}[<angle>]..repeated..
757 (<coor>){<label>}[<angle>]; (<dot size>)
758 % defaults
759 *[tzdot=2.4pt](<m>){}[]..repeated..(){}[]; (2.4pt)
760 % <m> means mandatory
761 \end{tzdef}
762
763
764 \begin{tzcode}{.3}
765 \begin{tikzpicture}
766 \tzhelplines(4,3)
767 \tzdots(0,0)(1,1)(2,1)(3,2)(4,3);
768 \tzdots*[red](0,3)(1,3)(2,3)(3,3)(4,2); % semicolon
769 \end{tikzpicture}
770 \end{tzcode}
771
772 Each coordinate can be labeled by specifying the optional argument |{<label>}| followed by |[<angle>]|. You can also change the size (\xem{diameter}) of the dots by specifying the \xem{last} parenthesis argument |(<dot size>)| \xem{after} the semicolon.
773
774 \begin{tzcode}{.3}
775 \begin{tikzpicture}
776 \tzhelplines(4,3)
777 \tzdots(0,0)(1,1){B}(2,1)(3,2){D}[-90](4,3);(10pt)
778 \tzdots*[fill=red](0,3){A}
779 (1,3){B}
780 (2,3){C}[-90]
781 (3,3)
782 (4,2){E}[[blue]0];(6pt) % diameter
783 \end{tikzpicture}
784 \end{tzcode}
785
786
787 %%------------------------------------------------------------
788 \section{Many coordinates: Semicolon versions}
789 \label{si:manycoordinates}
790
791 \subsection{\protect\cmd{\tzcoors}, \protect\cmd{\tzcoors*}}
792 \label{ssi:tzcoors}
793
794 |\tzcoor| accepts \xem{a pair} of mandatory arguments in parentheses: |(<coor>)(<name>)|.
795 The semicolon version macro \icmd{\tzcoors} accepts \xem{an arbitrary number of pairs} to define multiple coordinates. A semicolon `|;|' is necessary to indicate when the repetition ends.
796
797 \begin{tzcode}{.3}
798 \begin{tikzpicture}
799 \tzhelplines(4,3)
800 \tzcoors(0,0)(A)
801 (1,1)(B)
802 (2,1)(C)
803 (3,3)(D)
804 (4,2)(E);
805 \tzlines(A)(B)(C)(D)(E); % semicolon
806 \end{tikzpicture}
807 \end{tzcode}
808
809 The options |{<label>}| and |[<angle>]| following \xem{each pair} of |(<coor>)| and |(<name>)| allow you to put |<label>| in the direction of |<angle>| around the coordinate.
810 Here, the repeating pattern is the quadruple |(<coor>)(<name>){<label>}[<angle>]|. The first two parenthesis arguments are mandatory and others are optional. The pattern is repeated until |\tzcoors| meets a semicolon |;|.
811
812 \begin{tzcode}{.3}
813 \begin{tikzpicture}
814 \tzhelplines(4,3)
815 \tzcoors(0,0)(A){A}
816 (1,1)(B)
817 (2,1)(C){C}[0]
818 (3,3)(D){D}[180]
819 (4,2)(E){E}[-90];
820 \tzlines(A)(B)(C)(D)(E);
821 \end{tikzpicture}
822 \end{tzcode}
823
824
825 The starred version \icmd{\tzcoors*} does one more thing: to print node dots.
826
827 \begin{tzcode}{.3}
828 \begin{tikzpicture}
829 \tzhelplines(4,3)
830 \tzcoors*(0,0)(A){A}
831 (1,1)(B)
832 (2,1)(C){C}[0]
833 (3,3)(D){D}[180]
834 (4,2)(E){E}[-90];
835 \end{tikzpicture}
836 \end{tzcode}
837
838
839
840 \subsection{\protect\cmd{\tzcoorsquick}}
841 \label{ssi:tzcoorsquick}
842
843 \icmd{\tzcoorsquick} is just to see the array of many coordinates at a glance.
844 |\tzcoorsquick| works like |\tzcoors|, but it automatically prints the name of each coordinate as its label, right at the point, by default.
845
846 \begin{tzcode}{.3}
847 \begin{tikzpicture}
848 \tzhelplines(4,3)
849 \tzcoorsquick(0,0)(A)
850 (1,1)(Best)
851 (2,1)(Case)
852 (3,3)(Done)
853 (4,2)(End); % semicolon
854 \end{tikzpicture}
855 \end{tzcode}
856
857 \subsection{\protect\cmd{\tzcoorsquick*}}
858 \label{ssi:tzcoorsquick*}
859
860 The starred version \icmd{\tzcoorsquick*} prints node dots and automatically puts the labels |above| (in the direction of |90| degree from) them, by default.
861
862 \begin{tzcode}{.3}
863 \begin{tikzpicture}
864 \tzhelplines(4,3)
865 \tzcoorsquick*(0,0)(A)
866 (1,1)(Best)
867 (2,1)(Case)
868 (3,3)(Done)
869 (4,2)(End){END!}[[blue]0];
870 \end{tikzpicture}
871 \end{tzcode}
872
873
874 %%------------------------------------------------------------
875 \section{\texttt{plot coordinates}: Semicolon versions}
876 \label{si:plotcoordinates}
877
878 \subsection{\protect\cmd{\tzplot*}: Mark dots with \texttt{[mark=*]}}
879 \label{ssi:tzplot*}
880
881 \icmd{\tzplot*} accepts an arbitrary number of coordinates to print bullets with the \xem{radius} (|mark size| in \Tikz) of |2pt|, which is the initial value in \Tikz. Since this is a semicolon version, the repetition of coordinates must be ended by |;|.
882
883 \begin{tzcode}{.3}
884 \begin{tikzpicture}
885 \tzhelplines(4,3)
886 \tzplot*(0,0)
887 (1,1)
888 (2,1)
889 (3,3)
890 (4,2) ; % semicolon
891 \end{tikzpicture}
892 \end{tzcode}
893
894 \begin{tztikz}
895 \tzplot*(0,0)(1,1)(2,1); % works like:
896 \draw [mark=*] plot coordinates {(0,0)(1,1)(2,1)};
897 \end{tztikz}
898
899 Each coordinate can be labeled by specifying the optional argument |{<text>}| followed by |[<angle>]|. With the option |[mark=o]| you can print hollow dots. You can also change the \xem{radius} of the marks by specifying the \xem{last} parenthesis argument |(<mark size>)| \xem{after} the semicolon.
900
901 \begin{tzcode}{.3}
902 \begin{tikzpicture}
903 \tzhelplines(4,3)
904 \tzplot*[mark=o](0,0){A}
905 (1,1){Best}
906 (2,1){Case}
907 (3,3){Done}
908 (4,2){END!}[[blue]0] ; (1.2pt)
909 \end{tikzpicture}
910 \end{tzcode}
911
912
913 \subsection{\protect\cmd{\tzplot}: Lines with \texttt{[tension=0]}}
914 \label{ssi:tzplot:lines}
915
916 \icmd{\tzplot} accepts an arbitrary number of coordinates and draws line segments connecting them. The repetition of coordinates must be ended by |;| (semicolon version).
917
918 \begin{tzcode}{.3}
919 \begin{tikzpicture}
920 \tzhelplines(4,3)
921 \tzplot(0,0)
922 (1,1)
923 (2,1)
924 (3,3){Done}
925 (4,2){END!}[[blue]0];
926 \end{tikzpicture}
927 \end{tzcode}
928
929 \begin{tztikz}
930 \tzplot(0,0)(1,1)(2,1); % works like:
931 \draw plot coordinates {(0,0)(1,1)(2,1)};
932 \end{tztikz}
933
934
935 \subsection{\protect\cmd{\tzplot*[draw]}: Lines with dots}
936
937 \icmd{\tzplot*}|[draw]| prints bullet marks at the specified coordinates and draws line segments connecting them. The repetition of coordinates must be ended by |;| (semicolon version).
938
939 \begin{tzcode}{.3}
940 \begin{tikzpicture}
941 \tzhelplines(4,3)
942 \tzplot*[draw](0,0)
943 (1,1)
944 (2,1)
945 (3,3)
946 (4,2){END!}[[blue]0];
947 \end{tikzpicture}
948 \end{tzcode}
949
950
951 \subsection{\protect\cmd{\tzplotcurve}: Curves with \texttt{[smooth,tension=1]}}
952 \label{ssi:tzplotcurve}
953
954 \icmd{\tzplotcurve} plots any number of coordinates with the default option |[smooth,tension=1]|, resulting in a \xem{curve} connecting the specified coordinates.
955 The repetition of coordinates must be ended by |;| (semicolon version).
956
957 \begin{tzcode}{.3}
958 \begin{tikzpicture}
959 \tzhelplines(4,3)
960 \tzplotcurve(0,0)
961 (1,1)
962 (2,1)
963 (3,3)
964 (4,2){END!}[[blue]0] ; % semicolon
965 \end{tikzpicture}
966 \end{tzcode}
967
968 \begin{tzdef}
969 % syntax: simplified
970 \tzplotcurve[<opt>]{<tension>}"<path name>"
971 (<coor>){<label>}[<angle>]..repeated..(<coor>){<label>}[<angle>];
972 % defaults
973 [smooth,tension=1]{1}""(<m>){}[]..repeated..(){}[];
974 % <m> means mandatory
975 \end{tzdef}
976
977 \begin{tztikz}
978 \tzplotcurve(0,0)(1,1)(2,1); % works like:
979 \draw [smooth,tension=1] plot coordinates {(0,0)(1,1)(2,1)};
980 \end{tztikz}
981
982 You can change the tension value by specifying the optional argument |{<tension>}|, before the first coordinate.
983
984 \begin{tzcode}{.3}
985 \begin{tikzpicture}
986 \tzhelplines(4,3)
987 \tzcoor(.5,.5)(A)
988 \tzplotcurve[blue]{2}(1,3)(A)(4,0);
989 \tzplotcurve[thick](1,3)(A)(4,0); % default: tension=1
990 \tzplotcurve[red]{.55}(1,3)(A)(4,0); % TikZ default
991 \tzplotcurve[dashed]{0}(1,3)(A)(4,0);
992 \end{tikzpicture}
993 \end{tzcode}
994
995
996
997
998 %%==================================
999 \chapter{An Intuitive Introduction III: Plotting Functions}
1000 \label{ci:introIII}
1001
1002
1003 %%------------------------------------------------------------
1004 \section{Axes}
1005 \label{si:axes}
1006
1007 \subsection{\protect\cmd{\tzaxes}}
1008 \label{ssi:tzaxes}
1009
1010 \begin{tzdef}
1011 % syntax: simplified
1012 \tzaxes[<opt>]<x-shift,y-shift>(<x1,y1>)(<x2,y2>)
1013 {<x-text>}[<x-opt>]{<y-text>}[<y-opt>]
1014 % defaults
1015 [->]<0,0>(0,0)(<m>){}[right]{}[above]
1016 % <m> means mandatory
1017 \end{tzdef}
1018
1019 \icmd{\tzaxes} draws the x-axis from |<x1>| to |<x2>| and the y-axis from |<y1>| to |<y2>|.
1020
1021 \begin{tzcode}{.3}
1022 \begin{tikzpicture}[scale=.5]
1023 \tzhelplines(-1,-1)(8,5)
1024 \tzaxes(-1,-1)(8,5) % basics
1025 \end{tikzpicture}
1026 \end{tzcode}
1027
1028 If |(<x1,y1>)| is omitted, it is regarded as |(0,0)|.
1029 And optionally the names of x-axis and y-axis can be printed at a specified place (by default, |[right]| for x-axis and |[above]| for y-axis).
1030
1031 \begin{tzcode}{.3}
1032 \begin{tikzpicture}[scale=.5]
1033 \tzhelplines(-1,-1)(8,5)
1034 \tzaxes[draw=blue](8,5){$x$}{$y$} %%
1035 \end{tikzpicture}
1036 \end{tzcode}
1037
1038 With the optional argument |<x-shift,y-shift>|, the axes are shifted accordingly. Two axes intersect at |(<x-shift,y-shift>)|, by default |(0,0)|.
1039
1040 \begin{tzcode}{.3}
1041 \begin{tikzpicture}[scale=.5]
1042 \tzhelplines(-1,-1)(8,5)
1043 \tzaxes(-1,-1)(8,5){$Q$}[b]{$P$}[l]
1044 \tzaxes[dashed,-]<2,1>(-1,-1)(8,5) % shift
1045 \end{tikzpicture}
1046 \end{tzcode}
1047
1048 \subsection{\protect\cmd{\tzaxes*}}
1049 \label{ssi:tzaxes*}
1050
1051 The starred version \icmd{\tzaxes*} is just to set the current state to a \iisw{bounding box} when the |\tzaxes| macro execution is completed. Use |\tzaxes*| before any larger graphics.
1052
1053 \begin{tzcode}{.3}
1054 \begin{tikzpicture}[scale=.5]
1055 \tzaxes*(8,5){$x$}{$f(x)$} % bounding box
1056 \tzhelplines(-2,-1)(10,8)
1057 \tzto[out=90,in=-135,dashed](-2,8)(12,-2)
1058 \tzbezier[blue](-1,-1)(3,-2)(7,12)(10,10)
1059 \end{tikzpicture}
1060 \end{tzcode}
1061
1062
1063 \subsection{\protect\cmd{\tzshoworigin}, \protect\cmd{\tzshoworigin*}}
1064 \label{ssi:tzshoworigin}
1065
1066 \icmd{\tzshoworigin} prints `$0$' (roughly) at the bottom left of the origin.
1067
1068 \begin{tzcode}{.3}
1069 \begin{tikzpicture}[scale=.5]
1070 \tzhelplines(-1,-1)(8,5)
1071 \tzshoworigin
1072 \tzaxes(-1,-1)(8,5)
1073 \end{tikzpicture}
1074 \end{tzcode}
1075
1076 \icmd{\tzshoworigin*} prints a \xem{node dot} with the size of |2.4pt| (by default) at the origin.
1077
1078 \begin{tzcode}{.3}
1079 \begin{tikzpicture}[scale=.5]
1080 \tzhelplines(-1,-1)(8,5)
1081 \tzshoworigin*
1082 \tzaxes(-1,-1)(8,5)
1083 \end{tikzpicture}
1084 \end{tzcode}
1085
1086 |\tzshoworigin*(<coor>){<text>}[<node opt>]| prints a node dot and text around |(<coor>)|, by default |(0,0)|. (Notice that the place where the |<text>| is printed at is not by |<angle>|. Instead, you can use the \xem{abbreviations} of \Tikz\ basic placement options such as |a|, |l|, |br|, ect. See Section \ref{s:stylenames}, for more details.)
1087
1088 \begin{tzcode}{.3}
1089 \begin{tikzpicture}[scale=.5]
1090 \tzhelplines(-1,-1)(8,5)
1091 \tzshoworigin*{$O_1$}
1092 \tzaxes(-1,-1)(8,5)
1093 \tzaxes[blue]<7,4>(8,5)(-1,-1)
1094 \tzshoworigin*(7,4){$O_2$}[ar]
1095 \end{tikzpicture}
1096 \end{tzcode}
1097
1098 Notice that, in the previous example, the two axes intersect at |(7,4)| by the shift option |<7,4>|.
1099
1100 \subsection{\protect\cmd{\tzaxisx}, \protect\cmd{\tzaxisy}}
1101 \label{ssi:tzaxesx}
1102
1103 \icmd{\tzaxisx} draws an x-axis from |<x1>| to |<x2>|.
1104
1105 \begin{tzdef}
1106 % syntax: simplified
1107 \tzaxisx[<opt>]<y-shift>{<x1>}{<x2>}{<text>}[<node opt>]
1108 % defaults
1109 [->,>=stealth]<0>{<m>}{<m>}{}[right]
1110 \end{tzdef}
1111
1112 \icmd{\tzaxisy} works similarly for the y-axis, except for the axis label position: |above| by default.
1113
1114 \begin{tzcode}{.3}
1115 \begin{tikzpicture}[scale=.5]
1116 \tzhelplines(-1,-1)(8,5)
1117 \tzaxisx{-1}{8}{$x$}
1118 \tzaxisy[draw=blue,thick]{-1}{5}{$y$}
1119 \tzaxisx[dashed,-]<2>{-1}{8}
1120 \tzaxisy[thick,<->]<1>{-1}{5}
1121 \end{tikzpicture}
1122 \end{tzcode}
1123
1124
1125 %%------------------------------------------------------------
1126 \section{Ticks}
1127 \label{si:tikzs}
1128
1129 \subsection{\protect\cmd{\tzticks}}
1130 \label{ssi:tzticks}
1131
1132 \icmd{\tzticks}|{<x-tick places>}{<y-tick places>}| prints tick labels for x- and y-axis at specified places, which are comma separated.
1133 By default, tick labels are the numbers specified.
1134
1135 \begin{tzcode}{.3}
1136 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1137 \tzhelplines(8,5)
1138 \tzshoworigin
1139 \tzaxes(-1,-1)(8,5)
1140 \tzticks{1,2,...,8} % x-ticks
1141 {1,2,...,5} % y-ticks
1142 \end{tikzpicture}
1143 \end{tzcode}
1144
1145 You can change the numbered labels, for example |{2,4,7}|, to any other form, by doing like, for example, |{2/mylabel,4,7}|. (Internally, |\tzticks| uses the |foreach| operation of \Tikz.)
1146
1147 \begin{tzcode}{.3}
1148 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1149 \tzhelplines(8,5)
1150 \tzshoworigin
1151 \tzaxes(-1,-1)(8,5)
1152 \tzticks{2/x,4/y,5.5/$z_1$,7}
1153 {1,2.5/$\frac25$,4}
1154 \end{tikzpicture}
1155 \end{tzcode}
1156
1157 \subsection{\protect\cmd{\tzticks*}}
1158 \label{ssi:tzticks*}
1159
1160 The starred version \icmd{\tzticks*} prints tick marks from |0pt| to |3pt| by default, without printing tick labels.
1161
1162 \begin{tzcode}{.3}
1163 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1164 %\tzhelplines(8,5)
1165 \tzshoworigin
1166 \tzaxes(-1,-1)(8,5)
1167 \tzticks*{1,2,...,7}
1168 {1,2,3,4}
1169 \end{tikzpicture}
1170 \end{tzcode}
1171
1172 You can change the length of tick marks, for example, like |(-2pt:3pt)| and |(-5pt:10pt)| as shown in the following example.
1173
1174 \begin{tzcode}{.3}
1175 \begin{tikzpicture}[scale=.5]
1176 \tzhelplines(-1,-1)(8,5)
1177 \tzaxes(-1,-1)(8,5)
1178 \tzticks*(-2pt:3pt){1,2,...,7}
1179 (-5pt:10pt){1,2,3,4}
1180 \end{tikzpicture}
1181 \end{tzcode}
1182
1183
1184 \subsection{\protect\cmd{\tzticksx(*)}, \protect\cmd{\tzticksy(*)}}
1185 \label{ssi:tztikcsx}
1186
1187 \icmd{\tzticksx} and \icmd{\tzticksy} prints x-tick labels and y-tick labels, respectively.
1188
1189 \begin{tzcode}{.3}
1190 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1191 \tzhelplines(8,5)
1192 \tzaxes(-1,-1)(8,5)
1193 \tzticksx{1/x,3/y,5/z,7}
1194 \tzticksy(-5pt:10pt){1,2,4/k}
1195 \end{tikzpicture}
1196 \end{tzcode}
1197
1198 \icmd{\tzticksx*} and \icmd{\tzticksy*} suppress tick labels for their corresponding axes, like |\tzticks*|.
1199
1200 \begin{tzcode}{.3}
1201 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1202 %\tzhelplines(8,5)
1203 \tzaxes(-1,-1)(8,5)
1204 \tzticksx*{1/x,3/y,5/z,7}
1205 \tzticksy*(-5pt:10pt){1,2,4/k}
1206 \end{tikzpicture}
1207 \end{tzcode}
1208
1209 You can see more details on |\tzticks| and its friends in Chaper \ref{c:ticks} on page \pageref{c:ticks}.
1210
1211
1212 %%------------------------------------------------------------
1213 \section{Projections on the axes}
1214 \label{si:projections}
1215
1216
1217 \subsection{\protect\cmd{\tzprojx(*)}, \protect\cmd{\tzprojy(*)}}
1218 \label{ssi:tzprojx}
1219
1220 \icmd{\tzprojx} draws a \xem{dotted line} (by default) from a specified coordinate to its projection point on the x-axis and prints text around (|[below]| by default) the projection point.
1221
1222 |\tzprojy| works similarly but for the projection point on the y-axis.
1223
1224 \begin{tzcode}{.3}
1225 \begin{tikzpicture}
1226 \tzhelplines(4,3)
1227 \tzaxes(4,3)
1228 \tzdot*(3,2){$(x_1,x_2)$}[45]
1229 \tzprojx(3,2){$x_1$}
1230 \tzprojy[solid,->,draw=blue](3,2){$x_2$}[bl]
1231 \end{tikzpicture}
1232 \end{tzcode}
1233
1234 \icmd{\tzprojx*} does one more thing. It prints a node dot (with |\tzdot*|) at a specified coordinate. |\tzprojy*| works similarly but for the projection point on the y-axis.
1235
1236
1237 \begin{tzcode}{.3}
1238 \begin{tikzpicture}
1239 %\tzhelplines(4,3)
1240 \tzaxes(4,3)
1241 \tznode(3,2){$(x_1,x_2)$}[ar]
1242 \tzprojx*(3,2){$x_1$}[xshift=-3pt]
1243 \tzprojy[->,dashed,draw=red](3,2){$x_2$}
1244 \tzprojx*(1.5,2.5){$a$}
1245 \tzprojy*(2.5,1.5){$b$}
1246 \end{tikzpicture}
1247 \end{tzcode}
1248
1249
1250 \subsection{\protect\cmd{\tzproj(*)}}
1251 \label{ssi:tzproj}
1252
1253 \icmd{\tzproj} combines |\tzprojx| and |\tzprojy|.
1254 And \icmd{\tzproj*} combines |\tzprojx*| and |\tzprojy*|.
1255
1256
1257 \begin{tzcode}{.3}
1258 \begin{tikzpicture}
1259 %\tzhelplines(4,3)
1260 \tzaxes(4,3)
1261 \tznode(3,2){$(x_1,x_2)$}[ar]
1262 \tzproj[<->,solid,draw=red](3,2){$x_1$}{$x_2$}
1263 \tzproj*(1.5,2.5){$a$}[xshift=3pt,text=blue]{$b$}
1264 \end{tikzpicture}
1265 \end{tzcode}
1266
1267
1268 %%------------------------------------------------------------
1269 \section{Plot functions}
1270 \label{si:plotfunctions}
1271
1272 \subsection{\protect\cmd{\tzfn}}
1273 \label{ssi:tzfn}
1274
1275 \icmd{\tzfn}|{<fn of \x>}[<a:b>]| plots a function of $x$ over the specified domain $[a:b]$, which means that $a\leq x \leq b$.
1276 Optionally, you can add |{<text>}| with |[<node opt>]| as shown in the following example.
1277
1278 \begin{tzdef}
1279 % syntax: simplified
1280 \tzfn[<opt>]"<path name>"{<fn of \x>}[<a:b>]{<text>}[<node dot>]
1281 % defaults
1282 []""{<m>}[<m>]{}[]
1283 % <m>: mandatory
1284 \end{tzdef}
1285
1286 \begin{tzcode}{.3}
1287 \begin{tikzpicture}[scale=.7]
1288 \tzhelplines(5,5)
1289 \tzaxes(5,5)
1290 \tzfn{(\x-1)^2}[0:3] % y=(x-1)^2
1291 \def\Gx{(\x-2)^2+1}
1292 \tzfn[dashed]{\Gx}[1:4]{$g(x)$}[r] % g(x)=(x-2)^2+1
1293 \tzfn[red]{sin(\x r)+3}[0:2*pi] % y=sin x
1294 \end{tikzpicture}
1295 \end{tzcode}
1296
1297 \begin{tztikz}
1298 \tzfn[dashed]{(\x-2)^2+1}[1:4]{$g(x)$}[r] % works like:
1299 \draw [dashed] plot [domain=1:4] (\x,{(\x-2)^2+1}) node [right] {$g(x)$};
1300 \end{tztikz}
1301
1302 You can name a path formed by |\tzfn| by specifying the optional argument |"<path name>"| right before the mandatory curly brace argument |{<fn of \x>}|. The name of a path is used to find intersection points.
1303
1304
1305 \begin{tzcode}{.3}
1306 \begin{tikzpicture}[scale=.7,font=\footnotesize]
1307 \tzhelplines(5,5)
1308 \tzaxes(5,5){$x$}{$y$}
1309 \def\bgt{4-\x}
1310 \def\IC{3/\x}
1311 \def\ICa{4/\x}
1312 \tzfn"bgt"{\bgt}[0:4] % name path = bgt
1313 \tzfn[blue]"IC"{\IC}[.75:4] % name path = IC
1314 \tzfn[red]{\ICa}[1:4] % name path = ICa (automatically)
1315 \end{tikzpicture}
1316 \end{tzcode}
1317
1318 \remark
1319 If the curly brace mandatory argument consists of \xem{only a macro name} like |{\Foo}|, the macro name |Foo| (without the backslash) is automatically assigned to the \xem{name of the path}. (See Section \ref{ss:tzfn:namepath} on page \pageref{ss:tzfn:namepath}, for more details.)
1320
1321 \subsection{\protect\cmd{\tzhfnat}, \protect\cmd{\tzhfn}: Horizontal lines}
1322 \label{ssi:tzhfn}
1323
1324 \icmd{\tzhfnat} accepts a value of $y$ and draws a horizontal line (the graph of a constant function) at $y$ from left to right of the \ixxw{current bounding box}, by default, unless you specify the optional argument |[<from:to>]|.
1325
1326 \begin{tzdef}
1327 % syntax
1328 \tzhfnat[<opt>]"<path name>"{<y-val>}[<from:to>]{<text>}[<node opt>]
1329 % defaults
1330 []""{<m>}[west:east (of current bounding box)]{}[]
1331 \end{tzdef}
1332
1333 \icmd{\tzhfn}|(<coor>)| accepts a coordinate, instead of the value of $y$, to draw a horizontal line at the value of $y$ coordinate of |(<coor>)|, ignoring the value of $x$ coordinate.
1334
1335 \begin{tzcode}{.3}
1336 \begin{tikzpicture}
1337 \tzhelplines(4,3)
1338 \tzhfnat{0} % value of y
1339 \tzhfnat[dashed]{1}[1:4]{Two}[l,at start] % value of y
1340 \tzcoors(0,2)(A)(0,3)(B);
1341 \tzhfn[blue](A)[0:3]{Three}[b,near end] % coordinate
1342 \tzhfn[->](B)[0:3]{Four}[r] % cooridnate
1343 \end{tikzpicture}
1344 \end{tzcode}
1345
1346
1347 \subsection{\protect\cmd{\tzvfnat}, \protect\cmd{\tzvfn}: Vertical lines}
1348 \label{ssi:tzvfn}
1349
1350 \icmd{\tzvfnat} draws a vertical line at $x$ from bottom to top of the |current bounding box| by default.
1351
1352 \begin{tzdef}
1353 % syntax: simplified
1354 \tzvfnat[<opt>]"<path name>"{<x-vale>}[<from:to>]{<text>}[<pos>]
1355 % defaults
1356 []""{<m>}[south:north (of current bounding box)]{}[]
1357 \end{tzdef}
1358
1359 \icmd{\tzvfn}|(<coor>)| accepts a coordinate, instead of the value of $x$. It draws a vertical line at the value of $x$ coordinate of |(<coor>)|, ignoring the value of $y$ coordinate.
1360
1361 \begin{tzcode}{.3}
1362 \begin{tikzpicture}
1363 \tzhelplines(4,3)
1364 \tzvfnat{0}
1365 \tzvfnat[dashed]{1}[1:3]{Two}[b,at start]
1366 \tzvfn[blue](2,0)[0:3]{Three}[a,near end,sloped]
1367 \tzvfn[->](3,0)[0:3]{Four}[r]
1368 \end{tikzpicture}
1369 \end{tzcode}
1370
1371
1372
1373 \subsection{\protect\cmd{\tzLFn}: Linear functions}
1374 \label{ssi:tzLFn}
1375
1376 \icmd{\tzLFn}|(<coor1>)(<coor2>)...| draws a \xem{linear function} passing through two points: |(<coor1>)| and |(<coor2>)|.
1377 |\tzLFn(<coor1>){<slope>}...| draws a linear function passing through one point, |(<coor1>)|, with the slope of |<slope>|. If two coordinates and a slope are all specified the option |{<slope>}| is ignored. The domain in the form of |[a:b]| is also a required argument.
1378
1379 \begin{tzcode}{.3}
1380 \begin{tikzpicture}[scale=.7,font=\footnotesize]
1381 \tzhelplines(5,5)
1382 \tzaxes(-1,-1)(5,5)
1383 \tzdots*(1,1)(3,2);
1384 \tzLFn(1,1)(3,2)[0:4]{two points}[r]
1385 \tzLFn(1,1){1.5}[0:3]{one point and a slope}[r]
1386 \end{tikzpicture}
1387 \end{tzcode}
1388
1389
1390
1391 %%------------------------------------------------------------
1392 \section{Intersection points}
1393 \label{si:intersections}
1394
1395 \subsection{Naming paths}
1396 \label{ssi:namingpaths}
1397
1398 In \Tikz, you can find \xem{intersection} points when two \xem{named paths} intersect. The name of a path is usually given by the option |[name path=<path name>]| in \Tikz.
1399
1400 With the package \pkg{tzplot}, you can name a path by specifying an optional argument within quotation marks such as |"<path name>"|.
1401 (Of course, you can also name a path in usual \Tikz\ way, like |[name path=<path name>]|.)
1402
1403 In this package, all macros (with a few exceptions) related to lines and curves accept this quote optional argument to name paths as follows:
1404
1405 \begin{verbatim}
1406 \tzline[<opt>]"<path name>"(<coor>)...
1407 \tzlines... "<path name>"(<coor>)...
1408 \tzto... "<path name>"(<coor>)...
1409 \tzfn... "<path name>"{<fn of \x>}...
1410 \tzLFn... "<path name>"(<coor>)...
1411 and more...
1412 \end{verbatim}
1413
1414 \begin{tztikz}
1415 \tzline[dashed]"foo"(1,1)(3,3) % works like
1416 \draw [dashed,name path=foo](1,1) -- (3,3);
1417 \end{tztikz}
1418
1419 In most cases, the quote optional arguments for naming paths are placed \xem{immediately before the first mandatory argument} of the |tzplot| macros.
1420
1421 \subsection{\protect\cmd{\tzXpoint(*)}: Intersection points of two paths}
1422 \label{ssi:tzXpoint}
1423
1424 For example, \icmd{\tzXpoint}|{path1}{path2}(A)| finds intersection points of |path1| and |path2| and names the first intersection point |(A)|. This intersection point can be referred to as |(A)| or |(A-1)|. If there are two or more intersection points found, they are called |(A)=(A-1)|, |(A-2)|, |(A-3)|, and so on.
1425
1426 \begin{tzcode}{.3}
1427 \begin{tikzpicture}
1428 \tzhelplines(4,3)
1429 \tzline"AA"(0,0)(3,2)
1430 \tzline"BB"(0,3)(3,0)
1431 \tzXpoint{AA}{BB}(X)
1432 \tzdot*(X){E}
1433 \end{tikzpicture}
1434 \end{tzcode}
1435
1436 \icmd{\tzXpoint*} prints a node dot at the first intersection point.
1437 You can label the point by specifying |{<text>}| and |[<angle>]| after the specified intersection name.
1438
1439 \begin{tzcode}{.3}
1440 \begin{tikzpicture}[scale=.7,font=\footnotesize]
1441 \tzhelplines(5,5)
1442 \tzaxes(5,5){$x$}{$y$}
1443 \def\bgt{4-\x}
1444 \def\IC{3/\x}
1445 \tzfn"bgt"{\bgt}[0:4] % name path = bgt
1446 \tzfn[blue]"IC"{\IC}[.75:4] % name path = IC
1447 \tzXpoint*{bgt}{IC}(E){$A$}[45] % first intersection
1448 \tzdot(E-2){$B$}[45](5pt) % second intersection
1449 \end{tikzpicture}
1450 \end{tzcode}
1451
1452 \remark
1453 You have to expect \Tikz\ to take a few seconds (or less) to find intersection points.
1454
1455 \subsection{\protect\cmd{\tzvXpointat(*)}, \protect\cmd{\tzvXpoint(*)}: Vertical intersection points}
1456 \label{ssi:tzvXpoint}
1457
1458 To find vertical intersection points at $x$ to a curve, you should specify a path name and either the value of $x$ or the coordinate $(x,y)$. Here the $y$ coordinate is ignored.
1459
1460 \icmd{\tzvXpointat}|{<path>}{<x>}(A)| finds vertical intersection points of |<path>| at $x=\texttt{<x>}$ and names it |(A)|.
1461 The starred version \icmd{\tzvXpointat*} additionally prints a node dot at the (first) intersection point.
1462
1463 The macro \icmd{\tzvXpoint} uses |(<coor>)|, while |\tzvXpointat| uses the value of $x$. Here the $y$ coordinate of |(<coor>)| is not important. |\tzvXpoint| is useful when you do not know the exact value of $x$ coordinate of |(<coor>)|.
1464 The starred version \icmd{\tzvXpoint*} additionally prints a node dot at the (first) intersection point.
1465
1466
1467 \begin{tzcode}{.3}
1468 \begin{tikzpicture}[scale=.7,font=\scriptsize]
1469 \tzhelplines(5,5)
1470 \tzaxes(5,5)
1471 \def\Fx{(\x-1)^2}
1472 \tzfn\Fx[0:3] % name path = Fx (automatically)
1473 \tzvXpointat{Fx}{2.5}(A)
1474 \tzvXpoint{Fx}(2.8,1)(B) % y=1 is ignored
1475 \tzproj*[->](A){$2.5$}{$f(2.5)$}
1476 \tzdot(B){$B$}[0]
1477 \end{tikzpicture}
1478 \end{tzcode}
1479
1480
1481 \subsection{\protect\cmd{\tzhXpointat(*)}, \protect\cmd{\tzhXpoint(*)}: Horizontal intersection points}
1482 \label{ssi:tzhXpoint}
1483
1484 \icmd{\tzhXpointat}|{<path>}{<y>}(A)| works like |\tzvXpointat{<path>}{<x>}(A)|, but it uses the value of $y$ instead of $x$.
1485 The starred version \icmd{\tzhXpointat*} additionally prints a node dot at the (first) intersection point.
1486
1487 \icmd{\tzhXpoint} uses |(<coor>)|, while |\tzhXpointat| uses the value of $y$.
1488 Here the $x$ coordinate of |(<coor>)| is ignored.
1489 The starred version \icmd{\tzhXpoint*} prints a node dot at the (first) intersection point.
1490
1491 \begin{tzcode}{.3}
1492 \begin{tikzpicture}[scale=.7,font=\scriptsize]
1493 \tzhelplines(5,5)
1494 \tzaxes(5,5)
1495 \def\Fx{(\x-1)^2}
1496 \tzfn\Fx[0:3] % name path = Fx (automatically)
1497 \tzhXpointat{Fx}{2.5}(A)
1498 \tzhXpoint{Fx}(1,2.8)(B) % x=1 is ignored
1499 \tzproj*[<-](A){$f^{-1}(2.5)$}{$y=2.5$}
1500 \tzdot(B){$B$}[0]
1501 \end{tikzpicture}
1502 \end{tzcode}
1503
1504 You can see more details on |\tzXpoint| and its friends in Chapter \ref{c:intersections} on page \pageref{c:intersections}.
1505
1506
1507 %%------------------------------------------------------------
1508 \section{Tangent lines and secant lines}
1509 \label{si:tangentlines}
1510
1511 \subsection{\protect\cmd{\tztangentat}}
1512 \label{ssi:tztangentat}
1513
1514 \icmd{\tztangentat}|{<path>}{<x>}[<a:b>]| draws a tangent line to |<path>| at $x=\texttt{<x>}$ over $x\in [a,b]$.
1515 The domain is a mandatory argument and should be of the form |[<from:to>]|.
1516
1517 \begin{tzdef}
1518 % syntax: simplified
1519 \tztangentat{<path>}{<x>}[<domain>]{<text>}[<node opt>]
1520 % defaults
1521 []{<m>}{<m>}[<m>]{}[]
1522 % <m> means mandatory
1523 \end{tzdef}
1524
1525
1526 \remark
1527 The slope of a tangent line drawn by |\tztangentat| is just approximate.
1528
1529 The line is drawn on the |behind| layer, by default.
1530
1531 You can also add some text next to the tangent line by specifying the optional arguments |{<text>}| and |[<node opt>]|, after the domain.
1532
1533 \begin{tzcode}{.3}
1534 \begin{tikzpicture}[scale=.7]
1535 \tzhelplines(5,5)
1536 \tzparabola[thick,blue]"curve"(0,1)(2,3)(4,2)
1537 \tzvXpointat*{curve}{1}
1538 \tzvXpointat*{curve}{3}
1539 \tztangentat{curve}{1}[0:3]
1540 \tztangentat[red]{curve}{3}[1:5]{tangent at $x=3$}[b]
1541 \end{tikzpicture}
1542 \end{tzcode}
1543
1544 \subsection{\protect\cmd{\tztangent}}
1545 \label{ssi:tztangent}
1546
1547 \icmd{\tztangent} works like |\tztangentat|, but it accepts a coordinate instead of the value of $x$.
1548
1549 |\tztangent{<path>}(<coor>)| draws a tangent line to |<path>| at the $x$ coordinate of |(<coor>)|. Here, the $y$ coordinate of |(<coor>)| is ignored. The line is drawn on the |behind| layer, by default.
1550
1551
1552 \begin{tzdef}
1553 % syntax: simplified
1554 \tztangent{<path>}(<coor>)[<from:to>]{<text>}[<node opt>]
1555 % defaults
1556 []{<m>}(<m>)[<m>]{}[]
1557 \end{tzdef}
1558
1559 \begin{tzcode}{.3}
1560 \begin{tikzpicture}[scale=.7]
1561 \tzhelplines(5,5)
1562 \tzparabola[thick,blue]"curve"(0,1)(2,3)(4,2)
1563 \tzvXpoint*{curve}(1,0)(A){A}[135]
1564 \tzvXpoint*{curve}(3,0)(B){B}[45]
1565 \tztangent{curve}(A)[0:3]
1566 \tztangent[red]{curve}(B)[1:5]{tangent at $B$}[b]
1567 \end{tikzpicture}
1568 \end{tzcode}
1569
1570
1571 See Section \ref{s:tangent} on page \pageref{s:tangent} for more details on |\tztangent| and |\tztangentat|.
1572
1573
1574 \subsection{\protect\cmd{\tzsecantat}, \protect\cmd{\tzsecant}}
1575 \label{ssi:tzsecant}
1576
1577 \icmd{\tzsecantat}|{<path>}{<x1>}{<x2>}| draws a secant line segment of |<path>| from $x_1=\texttt{<x1>}$ to $x_2=\texttt{<x2>}$ on the |behind| layer, by default.
1578
1579 \begin{tzcode}{.3}
1580 \begin{tikzpicture}[scale=.7]
1581 \tzhelplines(5,5)
1582 \tzaxes*(5,5)
1583 \tzparabola"curve"(0,1)(2,3)(5,1)
1584 \tzsecantat{curve}{1}{2}
1585 \tzsecantat[red]{curve}{1}{3}
1586 \tzsecantat[blue]{curve}{1}{4}
1587 \end{tikzpicture}
1588 \end{tzcode}
1589
1590 \icmd{\tzsecant} works like |\tzsecantat|, but it accepts two coordinates instead of two values of $x$.
1591
1592 |\tzsecant{<path>}(<coor1>)(<coor2>)| draws a secant line segment of |<path>| from the $x$ coordinate of |(<coor1>)| to the $x$ coordinate of |(<coor2>)|, ignoring $y$ values of the coordinates, on the |behind| layer by default.
1593
1594 \begin{tzcode}{.3}
1595 \begin{tikzpicture}[scale=.7]
1596 \tzhelplines(5,5)
1597 \tzaxes(5,5)
1598 \tzparabola"curve"(0,1)(2,3)(5,1)
1599 \tzsecant{curve}(1,0)(2,0)
1600 \tzsecant[red]{curve}(1,0)(3,0)
1601 \tzsecant[blue,dashed]{curve}(1,0)(4,0)
1602 \end{tikzpicture}
1603 \end{tzcode}
1604
1605
1606 You can extend or shorten a secant line by specifying the domain |[<from:to>]|, which is an optional argument.
1607 If you specify the domain, |\tzsecant| draws a secant line over the domain.
1608 You can also add some text next to the secant line by specifying the optional arguments |{<text>}| and |[<node opt>]|.
1609
1610 \begin{tzcode}{.3}
1611 \begin{tikzpicture}[scale=.7]
1612 \tzhelplines[use as bounding box](5,5)
1613 \tzaxes(5,5)
1614 \tzparabola"curve"(0,1)(2,3)(5,1)
1615 \tzsecant{curve}(1,0)(2,0)
1616 \tzsecant[red]{curve}(1,0)(3,0)[0:5]{secant}[r]
1617 \tzsecantat[blue,dashed]{curve}{1}{4}[0:5]{blue}[r]
1618 \end{tikzpicture}
1619 \end{tzcode}
1620
1621 See Section \ref{s:secant} on page \pageref{s:secant} for more details on |\tzsecant| and |\tzsecantat|.
1622
1623 %%==================================
1624 \chapter{Examples: Economics}
1625 \label{ci:examples}
1626
1627 %%------------------------------------------------------------
1628 \section{Markets}
1629 \label{si:markets}
1630
1631 \subsection{Market equilibrium: step by step}
1632 \label{ssi:mkteqm}
1633
1634 \paragraph{Step 1} Determine the size of the graph.
1635
1636 \begin{tzcode}{.3}
1637 \begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
1638 % to avoid `dimension too large' error: x/y=0.05cm
1639 \tzhelplines[step=.5cm](110,110)
1640 \tzaxes(110,110){$Q$}{$P$}
1641 %\tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
1642 %\tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
1643 %\tzXpoint*{dem}{supp}(eqm){$E$}
1644 %\tzproj(eqm){$Q^*$}{$P^*$}
1645 \end{tikzpicture}
1646 \end{tzcode}
1647
1648 \paragraph{Step 2} Draw the demand and supply curves.
1649 Here, we are using |\tzto|.
1650
1651 \begin{tzcode}{.3}
1652 \begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
1653 % to avoid `dimension too large' error: x/y=0.05cm
1654 \tzhelplines[step=.5cm](110,110)
1655 \tzaxes(110,110){$Q$}{$P$}
1656 \tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
1657 \tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
1658 %\tzXpoint*{dem}{supp}(eqm){$E$}
1659 %\tzproj(eqm){$Q^*$}{$P^*$}
1660 \end{tikzpicture}
1661 \end{tzcode}
1662
1663 \paragraph{Step 3} Find an equilibrium point and name it. Use the starred version |\tzXpoint*| to print a dot and then label the point.
1664
1665 \begin{tzcode}{.3}
1666 \begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
1667 % to avoid `dimension too large' error: x/y=0.05cm
1668 \tzhelplines[step=.5cm](110,110)
1669 \tzaxes(110,110){$Q$}{$P$}
1670 \tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
1671 \tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
1672 \tzXpoint*{dem}{supp}(eqm){$E$}
1673 %\tzproj(eqm){$Q^*$}{$P^*$}
1674 \end{tikzpicture}
1675 \end{tzcode}
1676
1677 \tmpclearpage
1678
1679 \paragraph{Step 4} If necessary, use |\tzproj| to draw projection lines with text around the projection points.
1680
1681 \begin{tzcode}{.3}
1682 \begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
1683 % to avoid `dimension too large' error: x/y=0.05cm
1684 %\tzhelplines[step=.5cm](110,110)
1685 \tzaxes(110,110){$Q$}{$P$}
1686 \tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
1687 \tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
1688 \tzXpoint*{dem}{supp}(eqm){$E$}
1689 \tzproj(eqm){$Q^*$}{$P^*$}
1690 \end{tikzpicture}
1691 \end{tzcode}
1692
1693 \subsection{Tax incidence: step by step}
1694 \label{ssi:taxincidence}
1695
1696 \begin{enumerate}[{Step} 1{:}]
1697 \item Determine the size of the graph.
1698 \end{enumerate}
1699
1700 \begin{tzcode}{.3}
1701 \begin{tikzpicture}[scale=.035,font=\scriptsize]
1702 \tzhelplines[step=10cm](120,120)
1703 \tzaxes(120,120){$Q$}{$P$}
1704 \end{tikzpicture}
1705 \end{tzcode}
1706
1707
1708 \begin{tzcode}{.3}
1709 \begin{tikzpicture}[scale=.035,font=\scriptsize]
1710 %\tzhelplines[step=10cm](120,120)
1711 \tzaxes(120,120){$Q$}{$P$}
1712 % step 2
1713 \def\demA{100-\x}
1714 \def\suppA{10+\x}
1715 \tzfn\demA[0:100]{$D$}[ar] % name path = \demA
1716 \tzfn\suppA[0:90]{$S$}[r] % name path = \suppA
1717 \tzXpoint*{demA}{suppA}(E){$E$}
1718 % step 3
1719 \tzfn[dashed]"suppB"{\suppA+20}[0:80]{$S'$}[ar]
1720 \tzXpoint*{demA}{suppB}(newE){$E'$}
1721 \tzproj(newE){$Q$}{$P_d$}
1722 % step 4
1723 \tzvXpoint{suppA}(newE)(vX)
1724 % step 5
1725 \tzprojy(vX){$P_s$}
1726 \tzprojy(E){$P^c$}
1727 % step 6
1728 \tzpath*[red](E)(newE)(vX);
1729 % step 7
1730 \tznode($(E)!10cm!(E-|0,0)$){}[pin={-70:SWL}]
1731 \end{tikzpicture}
1732 \end{tzcode}
1733
1734
1735 \begin{enumerate}\addtocounter{enumi}{1}\renewcommand{\labelenumi}{{Step} \theenumi{:}}\firmlist
1736 \item Define functions and plot them. And then, find an intersection point.
1737 \item Draw the shifted supply curve and find new equilibrium point. And then, project the point on each axis.
1738 \item To illustrate the social welfare loss (SWL), find a vertical intersection point of the original supply curve using new equilibrium point.
1739 \item Project both of the old equilibrium point and the vertical intersection point onto the $y$ axis and add text.
1740 \item Fill the area of the social welfare loss with color.
1741 \item Add text `SWL' at the appropriate place.
1742 \end{enumerate}
1743
1744
1745 %%------------------------------------------------------------
1746 \section{Firms}
1747 \label{si:firms}
1748
1749 \subsection{Cost curves}
1750 \label{ssi:costcurves}
1751
1752 \begin{tzcode}{.3}
1753 \begin{tikzpicture}[scale=.4,font=\scriptsize]
1754 \tzhelplines(10,10)
1755 \tzaxes(10,10){$q$}{$AC$\\$AVC$\\$MC$}[align=center]
1756 \tzparabola"MC"(.5,4)(2,2)(6,9){$MC$}[a]
1757 \tzhXpointat{MC}{5}(A)
1758 \tzhXpointat{MC}{3}(B) % (B-2) will be used!
1759 \tzdots*(A)(B-2);
1760 \tzparabola(2,7)(A)(8,9){$AC$}[r]
1761 \tzparabola(1,4.5)(B-2)(8,8){$AVC$}[r]
1762 \end{tikzpicture}
1763 \end{tzcode}
1764
1765 \subsection{Equilibrium of a competitive firm}
1766 \label{ssi:competitive}
1767
1768 \begin{tzcode}{.3}
1769 \begin{tikzpicture}[scale=.4,font=\scriptsize]
1770 %\tzhelplines(10,10)
1771 \tzaxes(10,10){$q$}{$P$\\$AC$\\$MC$}[align=center]
1772 \tzparabola"MC"(2,2)(6,9){$MC$}[a]
1773 \tzhXpointat{MC}{4}(A) % point (A) on MC at q=4
1774 \tzparabola"AC"(2,7)(A)(8,9){$AC$}[r] % (A): minAC
1775 \tzhfnat[blue]"price"{6}[0:9]{$P$}[l,at start]
1776 \tzXpoint*{price}{MC}(E)
1777 \tzprojx(E){$q^*$}
1778 \tzvXpoint{AC}(E)(ACeqm) % point on AC in eqmuilibrium
1779 \tzprojy(ACeqm){$AC(q^*)$}
1780 \tzpath*[red](E-|0,0)(E)(ACeqm)(ACeqm-|0,0);
1781 \tznode(2,5){$\pi^*$}
1782 \end{tikzpicture}
1783 \end{tzcode}
1784
1785
1786 \subsection{Monopoly equilibrium}
1787 \label{ssi:monopoly}
1788
1789 \begin{tzcode}{.3}
1790 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1791 %\tzhelplines(10,10)
1792 \tzaxes(10,10){$Q$}{$P$}
1793 \def\DD{8-\x}
1794 \def\MR{8-2*\x}
1795 \def\MC{\x}
1796 \tzfn\DD[0:8]{$D$}[ar]
1797 \tzfn\MR[0:4.5]{$MR$}[r]
1798 \tzfn\MC[0:7]{$MC$}[r]
1799 \tzXpoint*{MR}{MC}(E)
1800 \tzvXpoint*{DD}(E)(EE)
1801 \tzproj(EE){$Q^M$}{$P^M$}
1802 \tzXpoint{DD}{MC}(C)
1803 \tzpath*(EE)(C)(E);
1804 \tznode(C){\tiny SWL}[l]
1805 \tzpath*[blue](0,8)(EE)(EE-|0,0);
1806 \tznode(1,6){C.S.}
1807 \tzpath[pattern=horizontal lines](0,0)(E)(E-|0,0);
1808 \tznode(1,2){P.S.}
1809 \end{tikzpicture}
1810 \end{tzcode}
1811
1812 %%------------------------------------------------------------
1813 \section{Consumers: Budget lines and indifference curves}
1814 \label{si:consumers}
1815
1816 \begin{tzcode}{.3}
1817 \begin{tikzpicture}[scale=.3,font=\scriptsize]
1818 %\tzhelplines(15,12)
1819 \tzaxes(15,12){$x$}{$y$}
1820 \def\bgt{-3/4*\x+9} % 3x+4y=36
1821 \tzfn\bgt[0:12]
1822 \tzvXpoint*{bgt}(6,0)(A){A}[45]
1823 \tzplotcurve"ICC"(3,9)(A)(12,3); % trial and error
1824 \tzproj(A){$x^*$}{$y^*$}
1825 \tzticks{12}{9}
1826 \end{tikzpicture}
1827 \end{tzcode}
1828
1829
1830 \begin{tzcode}{.3}
1831 \begin{tikzpicture}[scale=.15,font=\scriptsize]
1832 %\tzhelplines(35,25)
1833 \tzaxes(35,25){$x$}{$y$}
1834 \def\bgt{-2/3*\x+20} % 2x+3y=60
1835 \def\IC{150/\x} % u(x,y)=xy
1836 \tzfn\bgt[0:30]
1837 \tzfn\IC[7:30]
1838 \tzcoor*(15,10)(E){$E$}[45]
1839 \tzproj(E)
1840 \tzticks{15,30}{10,20}
1841 \tzvXpointat*[red]{IC}{12}(A)
1842 \tztangent[blue,densely dashed]{IC}(A)[5:20]
1843 \end{tikzpicture}
1844 \end{tzcode}
1845
1846
1847 %%------------------------------------------------------------
1848 \section{Production Possibility Curves}
1849 \label{si:PPC}
1850
1851 \begin{tzcode}{.3}
1852 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1853 \tzhelplines(9,8)
1854 \tzaxes(9,8){$X$}{$Y$}
1855 \tzto[out=-10,in=105]"PPC"(0,7)(6,0){PPC}[ar]
1856 \tzvXpointat*{PPC}{2}(E)
1857 \tztangent[blue]"tan"{PPC}(E)[0:8]
1858 \tzvXpointat*{tan}{4}(F)
1859 \tzplotcurve[densely dashed,red](2,7)(F)(8,4);
1860 \end{tikzpicture}
1861 \end{tzcode}
1862
1863
1864
1865
1866 %%------------------------------------------------------------
1867 \section{Edgeworth box}
1868 \label{si:edgeworth}
1869
1870 \begin{tzcode}{.3}
1871 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1872 %\tzhelplines(9,7)
1873 \tzaxes(9,7){$x_1$}{$y_1$}
1874 \tzaxes<8,6>(8,6)(-1,-1){$x_2$}[l]{$y_2$}[b]
1875 \tzshoworigin{$O_1$}
1876 \tzshoworigin(8,6){$O_2$}[ar]
1877 \tzto[bend right](2,5)(7,2){$u_1$}[r]
1878 \tzto[bend left](1,4)(6,1){$u_2$}[b]
1879 \end{tikzpicture}
1880 \end{tzcode}
1881
1882
1883 %%------------------------------------------------------------
1884 \section{Growth}
1885 \label{si:growth}
1886
1887 \begin{tzcode}{.3}
1888 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1889 %\tzhelplines(10,8)
1890 \tzshoworigin
1891 \tzaxes*(10,8){$k$}{$y$} % bounding box
1892 \def\Fk{3*(\x)^(1/3)}
1893 \def\sFk{2*(\x)^(1/3)}
1894 \def\ndk{7/9*\x}
1895 \tzfn\Fk[0:9]{$y=f(k)$}[r] % name path=Fk
1896 \tzfn\sFk[0:9]{$sf(k)$}[r] % name path=sFk
1897 \tzfn\ndk[0:9]{$(n+\delta)k$}[r] % name path=ndk
1898 \tzXpoint*{sFk}{ndk}(E)[2]{$E$}[135] % (E)=(E-2)
1899 \tzvXpoint*{Fk}(E)(YE) % 2nd X point
1900 \tzproj(YE){$k^*$}{$y^*$}
1901 \tzvXpointat*{Fk}{2}(A)
1902 \tzvXpointat*{sFk}{2}(B)
1903 \tzvXpointat*{ndk}{2}(C)
1904 \tzproj(A){$k_0$}{$y_0$}
1905 \tzprojy(B){$sf(k_0)$}
1906 \tzprojy(C){$(n+\delta)k_0$}
1907 \end{tikzpicture}
1908 \end{tzcode}
1909
1910
1911
1912 %%------------------------------------------------------------
1913 \section{Liquidity trap}
1914 \label{si:trap}
1915
1916 \begin{tzcode}{.3}
1917 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1918 %\tzhelplines(10,8)
1919 \tzshoworigin
1920 \tzaxes(10,8){$Y$}{$r$}
1921 \tzline"LM"(1,2)(5,2)
1922 \tzto[out=0,in=-95](5,2)(8,6){$LM$}[a]
1923 \tzto[dashed,out=0,in=-95](5,2)(9.5,6){$LM'$}[a]
1924 \tzLFn"IS"(4,2){-1}[5:1]{$IS$}[a]
1925 \tzLFn[dashed]<1,0>"ISa"(4,2){-1}[5:1]{$IS'$}[a] %%
1926 \tzXpoint{IS}{LM}(E)
1927 \tzXpoint{ISa}{LM}(E1)
1928 \tzproj(E){$Y^*$}{$r_0$}
1929 \tzprojx(E1){$Y'$}
1930 \end{tikzpicture}
1931 \end{tzcode}
1932
1933 $LM$ curves are drawn with two paths.
1934 To shift the $IS$ curve, |<shift coor>| is used. See Section \ref{s:tzLFn} on page \pageref{s:tzLFn} for more details.
1935
1936
1937 \begin{tzcode}{.3}
1938 \begin{tikzpicture}[scale=.5,font=\scriptsize]
1939 %\tzhelplines(10,8)
1940 \tzshoworigin
1941 \tzaxes(10,8){$m$}{$r$}
1942 \tzto[out=-88,in=180](1,7)(5,2)
1943 <--(9,2) node [r] {$m^d$}> % code.append
1944 \tzvfnat{5}[0:6]{$m^s_0$}[a]
1945 \tzvfnat{6.5}[0:6]{$m^s_1$}[a]
1946 \tzvfnat{8}[0:6]{$m^s_2$}[a]
1947 \tzprojy(5,2){$r_0$}
1948 \tzticksx{5/{$m_0$},6.5/{$m_1$},8/{$m_2$}}
1949 \end{tikzpicture}
1950 \end{tzcode}
1951
1952 The money demand ($m_d$) curve is drawn with one path.
1953 To do this, |<code.append>| is used.
1954 See Section \ref{s:tzto} on page \pageref{s:tzto} for more details.
1955
1956
1957 %%------------------------------------------------------------
1958 \section{Miscellany}
1959 \label{si:misc}
1960
1961
1962 \begin{tzcode}{.3}
1963 \begin{tikzpicture}[font=\scriptsize]
1964 \def\z{1}
1965 \tzcoors
1966 (0,0)(A)
1967 ($(A) + (45:\z)$)(B)
1968 ($(B) + (45:\z)$)(C)
1969 ($(A) + (-45:\z)$)(D)
1970 ($(D) + (45:\z)$)(E)
1971 ($(E) + (45:\z)$)(F)
1972 ($(D) + (-45:\z)$)(G)
1973 ($(G) + (45:\z)$)(H)
1974 ($(H) + (45:\z)$)(I);
1975
1976 \foreach \a in {A,...,I}
1977 { \tzdot*(\a){\a}
1978 }
1979
1980 \tzlines(D)(A)(B)(C)(F)(E)(D)(G)(H)(I)(F);
1981 \tzlines[red](B)(E)(H);
1982 \end{tikzpicture}
1983 \end{tzcode}
1984
1985
1986
1987 \begin{tzcode}{.3}
1988 \begin{tikzpicture}[scale=1,font=\scriptsize]
1989 \tzaxes(4,4){alternatives}{preferences}
1990 \tzticksx{1/$a$,2/$b$,3/$c$}
1991 \tzplot[mark=ball](1,3)(2,2)(3,1){A}[0];
1992 \tzplot[mark=*] (1,2)(2,1)(3,3){B}[0];
1993 \tzplot[mark=+] (1,1)(2,3)(3,2){C}[0];
1994 \end{tikzpicture}
1995 \end{tzcode}
1996
1997
1998 \begin{tzcode}{.3}
1999 \begin{tikzpicture}[scale=1,font=\scriptsize]
2000 \tzaxes(4,4){alternatives}{preferences}
2001 \tzticksx{1/$a$,2/$b$,3/$c$}
2002 \foreach \x in {1,2,3}
2003 {\foreach \y in {1,2,3}
2004 {\tzdot*(\x,\y)}
2005 }
2006 \tzlines(1,3)(2,2)(3,1){A}[r];
2007 \tzlines(1,2)(2,1)(3,3){B}[r];
2008 \tzlines(1,1)(2,3)(3,2){C}[r];
2009 \end{tikzpicture}
2010 \end{tzcode}
2011
2012