PSTricksLecture Summer 2011
PSTricksLecture Summer 2011
2. PSTricks Examples
1. Resources
30
(a) ImageMagick is a collection of (free) image manipulation tools. You can nd out more by visiting http://www.imagemagick.com
A (b) The L TEX Graphics Companion. - Paperback: 608 pages - Publisher: Addison-Wesley Pub Co; 1st edition (April 15, 1997) - ISBN: 0201854694
25 20 15 10 5 5 4 3 2 1 1 2 3 4 5
y = x2
A (c) The L TEX Graphics Companion (2nd Edition). - Paperback: 976 pages - Publisher: Addison-Wesley Professional; 2 edition (August 12, 2007) - ISBN: 0321508920
r- Coordinate System
3
(d) The PSTricks web site. http://tug.org/PSTricks/ (e) PostScript(R) Language Tutorial and Cookbook (also called the The Blue Book) - Paperback: 256 pages - Publisher: Addison-Wesley Professional (January 1, 1985) - ISBN: 0201101793
r = 1 + 2 sin
1 1
r = 1 + 2 sin
3
(c)
1
1 P (2, 6)
(b)
(a)
v u u+v v
y
r = g2 () r=a =
xy = c
P0
1
r = g1 ()
z z
x C y
1
x 9 10
3. PSTricks To use PSTricks you must include the following lines in the preamble of your document.
1 2 3 4 5 6 7
2 3
We should mention that there have been some incompatibilities between the pstcol package (used by PSTricks) and the graphics packages mentioned above. Using colors with PSTricks is similar to what has already been discussed. The real power of the PSTricks package is the ability to create graphics using LaTeX-like syntax.
1 2 3 4 5 6
The previous example might be easier to understand if we include more detail in the sketch. Thus %\begin{pspicture}(-6,-6)(6,6) \showgrid \psline[linecolor=blue,linewidth=1.5pt ,doubleline=true% ,arrowscale=2,arrows=->](-3,1)(2,2) %\end{pspicture}
11
12
Heres another example. Observe that the default unit length is controlled by the macro \psset. For example, \psset{unit=12mm} . (Note: 10mm is the default value.)
1 2 3 4 5 6 7 8
(b) Basic Graphics Objects Heres a curve. Notice that the points used to generate the curve can be turned on (as shown) or o.
1 2 3 4 5
9 10 11
%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \psset{unit=10mm} \showgrid \myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax) \pscurve[linecolor=red,linewidth=1.5pt ,showpoints=true] (\xmin,1)(0,2)(3,1)(\xmax,\ymax) \psbezier[style=myCurveStyle ,linecolor=blue,showpoints=true]{-}% (-4,-1)(-2,-3)(1,-4)(5,-2) %\end{pspicture}
Here the values \xmin, \ymin, etc. have been previously dened. For example,
1 2
\def\xmin{-6}\def\xmax{6} \def\ymin{-2}\def\ymax{6}
13
14
Here is a circle centered at (2, 1) of radius 2. %\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \showgrid \pscircle[linecolor=red,linewidth=1.5pt] (-2,-1){2} %\end{pspicture}
1 2 3 4 5
(0, 0)
2 3 4 5 6 7 8
15
16
Finally, we plot some functions. To do this well use some custom macros that give the user better control over the coordinate system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
40 35 30
\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \showgrid \pstVerb{% /f@ {dup mul} def % x^2 } %%%%%%%%%%%%%%%%%%%% %% Axes and Ticks %% %%%%%%%%%%%%%%%%%%%% \myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax) \xTickMarks{\xmin}{\xmax}{1} \yTickMarks{\ymin}{\ymax}{5} %%%%%%%%%%%%%%%%%%%%%%% %% Graphical Objects %% %%%%%%%%%%%%%%%%%%%%%%% \psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)} \psplot[style=myPlotStyle,linecolor=blue] {\xmin}{\xmax}{x f@} \endpsclip %%%%%%%%%%%% %% Labels %% %%%%%%%%%%%% \SpecialCoor \uput{6pt}[0](!3 dup f@){$y=x^2$} \NormalCoor \end{pspicture}
25 20 15 10 5 0 5 6 5 4 3 2 1 0 1 2 3 4 5 6
y = x2
y = cos x
17
18
0 0 1 2 3 4 5 6
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
\def\xmin{0}\def\xmax{6} \def\ymin{0}\def\ymax{1} \def\dommin{\xmin}\def\dommax{\xmax} \VR{3in}{2.5in} \newpsobject{newgrid}{psgrid}{% gridlabels=0pt% ,griddots=0% ,gridwidth=0.5pt% ,gridcolor=gray% ,subgriddiv=4% ,subgridwidth=0.25pt% ,subgridcolor=red} \begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \newgrid %%%%%%%%%%%%%%%%%%%% %% Axes and Ticks %% %%%%%%%%%%%%%%%%%%%% \SpecialCoor %% Labels go here \rput[lr](!\xmax\space\xmax\space\xmin\space sub 15 div sub \ymax\space\ymax\space\ymin\space sub 25 div sub){$y=\dfrac{1}{x}$} \NormalCoor \myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax) %% Change these as needed. #1 - start, #2 - end, %% #3 - increment \xTickMarks{\xmin}{\xmax}{1} \yTickMarks{\ymin}{\ymax}{1} \psclip{\psframe(\xmin,\ymin)(\xmax,\ymax)} %% Graphing directives go here, e.g., \psplot[style=myPlotStyle] {0.1}{\xmax}{1 x div} \endpsclip \SpecialCoor \psline[fillstyle=crosshatch]{-}(3,0)(3.5,0)(!3.5 1 3 div)(!3 1 3 div)(3,0) \psline[fillstyle=crosshatch]{-}(3.5,0)(4,0)(!4 1 3.5 div)(!3.5 1 3.5 div)(3.5,0) \psline[fillstyle=crosshatch]{-}(4,0)(4.5,0)(!4.5 1 4 div)(!4 1 4 div)(4,0) \psline[fillstyle=crosshatch]{-}(4.5,0)(5,0)(!5 1 4.5 div)(!4.5 1 4.5 div)(4.5,0) 20
19
43 44
\NormalCoor \end{pspicture}
(c) Plotting Data from a File Suppose that you wish to plot the following data. 0, 0.0628, 0.1256, ... The following code does the trick.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \showgrid %% Axes and Ticks %% \myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax) %% Graphical Objects %% \psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)} \fileplot[linecolor=blue,linewidth=1.5pt] {plotData.txt} \endpsclip \SpecialCoor \rput[lt](!\xmax\space\xmin\space sub 15 div \ymax\space\ymax\space\ymin\space sub 25 div sub) {$y=\sin x$} \NormalCoor %\end{pspicture} y = sin x
21
22
A 30 80 E
C D
1
80 60 50
40 77
53
P T R A C
23
24
y y x x
25
26
f (x, y, z ) = c
f (xk , yk , zk )
Pk
vk
uk k
Ak
27
28