LATEX Graphics with PSTricks
This presentation is also available online. Please visit my home page and follow the links.
http://www.math.msu.edu/∼hensh
1. Resources
(a) ImageMagick is a collection of (free) image manipulation tools. You can find out more byvisiting
http://www.imagemagick.com
(b) The LATEX Graphics Companion.
- Paperback: 608 pages
- Publisher: Addison-Wesley Pub Co; 1st edition (April 15, 1997)
- ISBN: 0201854694
(c) The LATEX Graphics Companion (2nd Edition).
- Paperback: 976 pages
- Publisher: Addison-Wesley Professional; 2 edition (August 12, 2007)
- ISBN: 0321508920
(d) PSTricks: Graphics and PostScript for TEX and LATEX.
- Paperback: 912 pages
- Publisher: UIT Cambridge Ltd. (September 1, 2011)
- ISBN: 1906860130
(e) The PSTricks web site.
https://www.tug.org/PSTricks
(f) PostScript(R) Language Tutorial and Cookbook (also called the “The Blue Book”)
- Paperback: 256 pages
- Publisher: Addison-Wesley Professional (January 1, 1985)
- ISBN: 0201101793
2. PSTricks
1
(a) We start with some examples.
−5 −4 −3 −2 −1 1 2 3 4 5
5
10
15
20
25
30
y = x2
Figure 1: Graphing simple functions.
1 2 3 4 5 6
−1
1
2
3
r = 1 + 2 sin θ
r-θ Coordinate System
Figure 2: Graphing with some fancy effects.
2
−2 −1 1 2
1
2
3
r = 1 + 2 sin θx-y Coordinate System
Figure 3: Polar Graphs
b
1
P (2, 6)
Figure 4: Area between two curves.
3
~u
~v
Figure 5: A pair of vectors
~u
~v
~v
~u + ~v
Figure 6: Vector addition with a grid.
4
π
12
1
bb
b
(a)(b)
(c)
Figure 7: Polar Grid
xy
z
Figure 8: Sketching a cylinder.
5
x
y
z
b
b
Figure 9: Position Vectors
Figure 10: Level Curves
6
θ = α
θ = β
r = g1(θ)
r = g2(θ)
r = a
Figure 11: Polar Area
xy
z
b
Figure 12: A Tangent Line
7
−1 1
−1
1
c = 0.01
c = 0.025
c = 0.05
c = 0.075
c = 0.1
c = 0.11
c = 0.125
b
xy = c
P0
Figure 13: Lagrange Multipliers
8
x
y
z
Figure 14: Exposed Solid
9
x
y
z
Figure 15: Surface Integrals
x
y
z
Figure 16: Distorted Surface
10
Figure 17: Fractals
11
Isn’tPSTricks
lots of fun
2013 !
Isn’tPSTricks
lots of fun
2013
Isn’tPSTricks
lots of fun
2013 !Figure 18: Lens Effects
−1 1 2 3
−1
1
2
C
Increasing Vector Magnitude
Figure 19: Vector Field
12
3. PSTricks
To use PSTricks you must include the following lines in the preamble of your document.
1 \usepackage{pst-eucl}
2 \usepackage{calc}
3 \usepackage{pst-3dplot}%
4 \usepackage{pst-grad}
5 \usepackage{pst-plot,pst-math,pstricks-add}%
6 \usepackage{pst-all}
7 %\RequirePackage{pst-xkey}
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 ofthe PSTricks package is the ability to create graphics using LATEX-like syntax.
13
(a) Preliminaries
PSTricks provides users with the capability to draw using the familiar syntax of LATEX.
1 \psline[linecolor=blue,linewidth=1.25pt](-3,1)(2,2)
The previous example might be easier to understand if we include more detail in thesketch. Thus
1 \showgrid
2 \psline[linecolor=blue,linewidth=1.25pt,arrowscale=2]{->}(-3,1)(2,2)
1 \newpsobject{showgrid}{psgrid}{%
2 gridlabels=0pt%
3 ,griddots=0%
4 ,gridwidth=0.5pt%
5 ,gridcolor=gray%
6 ,subgriddiv=0%
7 ,subgridwidth=0.25pt%
8 ,subgridcolor=red}
14
(b) Basic Graphics Objects
Here’s a curve. Notice that the points used can be turned on (as shown) or off.
1 %\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
2 \showgrid
3 \pscurve[linecolor=red,linewidth=1.5pt,showpoints=true]%
4 (\xmin,1)(0,2)(3,1)(\xmax,\ymax)
5 %\end{pspicture}
bb
b
b
where the values \xmin, \ymin, etc. have been defined previously as
1 \def\xmin{-6}\def\xmax{6}
2 \def\ymin{-6}\def\ymax{6}
15
We begin by setting the default unit(s) in PSTricks using the command\psset{unit=1cm} . This is actually the default value.
1 %\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
2 \showgrid
3 \pscurve[linecolor=red,linewidth=1.5pt,showpoints=true]
4 (\xmin,1)(0,2)(3,1)(\xmax,\ymax)
5 \psbezier[style=myCurveStyle,linecolor=green]{-}%
6 (-4,1)(-2,3)(1,-4)(5,5)
7 %\end{pspicture}
bb
b
b
There are built-in shapes
1 %\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
2 \showgrid
3 \psellipse[linecolor=blue,linewidth=1.5pt]
4 (1,0)(1,1.5)
5 \psdots[linecolor=red,linewidth=1.25pt](0,0)
6 \SpecialCoor
7 \uput{6pt}[180](0,0){$(0,0)$}
8 \NormalCoor
9 %\end{pspicture}
b(0, 0)
16
Here is a circle centered at (−2, −1) of radius 2.
1 %\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
2 \showgrid
3 \pscircle[linecolor=red,linewidth=1.5pt]
4 (-2,-1){2}
5 %\end{pspicture}
Here is the same object filled-in and clipped.
1 %\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
2 \showgrid
3 \psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)}
4 \pscircle*[linecolor=red,linewidth=1.5pt]
5 (-2,-1){2}
6 \endpsclip
7 \pswedge*[linecolor=white](-2,-1){1}{15}{105}
8 %\end{pspicture}
17
Finally, we plot some functions. To do this we’ll use some custom macros that give theuser better control over the coordinate system.
1 \begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
2 \showgrid
3 \pstVerb{%
4 /f@ {dup mul} def % x^2
5 }
6 %%%%%%%%%%%%%%%%%%%%
7 %% Axes and Ticks %%
8 %%%%%%%%%%%%%%%%%%%%
9 \myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax)
10 \xTickMarks{\xmin}{\xmax}{1}
11 \yTickMarks{\ymin}{\ymax}{5}
12 %%%%%%%%%%%%%%%%%%%%%%%
13 %% Graphical Objects %%
14 %%%%%%%%%%%%%%%%%%%%%%%
15 \psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)}
16 \psplot[style=myPlotStyle]
17 {\xmin}{\xmax}{x f@}
18 \endpsclip
19 %%%%%%%%%%%%
20 %% Labels %%
21 %%%%%%%%%%%%
22 \SpecialCoor
23 \uput{6pt}[0](!3 dup f@){$y=x^2$}
24 \NormalCoor
25 \end{pspicture}
18
−6 −5 −4 −3 −2 −1 0 1 2 3 4 5 6−5
0
5
10
15
20
25
30
35
40
y = x2
And again, using better grid controls.
−6 −5 −4 −3 −2 −1 0 1 2 3 4 5 6−5
0
5
10
15
20
25
30
35
40y = x2
19
Here’s something useful for integration theory. Use the sketch to estimate the integralbelow.
∫
5
2
1
xdx
y =1
x
1 2 3 4 5 6
1
20
Here is the code
1 \def\xmin{0}\def\xmax{6}
2 \def\ymin{0}\def\ymax{1}
3 \def\dommin{\xmin}\def\dommax{\xmax}
4 \VR{3in}{2.5in}
5
6 \newpsobject{newgrid}{psgrid}{%
7 gridlabels=0pt%
8 ,griddots=0%
9 ,gridwidth=0.5pt%
10 ,gridcolor=gray%
11 ,subgriddiv=4%
12 ,subgridwidth=0.25pt%
13 ,subgridcolor=red}
14 \begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
15 \newgrid
16 %%%%%%%%%%%%%%%%%%%%
17 %% Axes and Ticks %%
18 %%%%%%%%%%%%%%%%%%%%
19 \SpecialCoor
20 %% Labels go here
21 \rput[lr](!\xmax\space\xmax\space\xmin\space sub 15 div sub
22 \ymax\space\ymax\space\ymin\space sub 25 div sub){$y=\dfrac{1}{x}$}
23 \NormalCoor
24 \myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax)
25 %% Change these as needed. #1 - start, #2 - end, #3 - increment
26 \xTickMarks{\xmin}{\xmax}{1}
27 \yTickMarks{\ymin}{\ymax}{1}
28 \psclip{\psframe(\xmin,\ymin)(\xmax,\ymax)}
29 %% Graphing directives go here, e.g.,
30 \psplot[style=myPlotStyle]
31 {0.1}{\xmax}{1 x div}
32 \endpsclip
33 \SpecialCoor
34 \psline[fillstyle=crosshatch]{-}(3,0)(3.5,0)(!3.5 1 3
35 div)(!3 1 3 div)(3,0)
36 \psline[fillstyle=crosshatch]{-}(3.5,0)(4,0)(!4 1 3.5
37 div)(!3.5 1 3.5 div)(3.5,0)
38 \psline[fillstyle=crosshatch]{-}(4,0)(4.5,0)(!4.5 1 4
39 div)(!4 1 4 div)(4,0)
40 \psline[fillstyle=crosshatch]{-}(4.5,0)(5,0)(!5 1 4.5
41 div)(!4.5 1 4.5 div)(4.5,0)
42 \NormalCoor
43 \end{pspicture}
21
(c) Plotting Data from a File
Suppose that you wish to plot the following data.
0, 00.0628, 0.062790.1256, 0.12533
... ...
The following code does the trick.
1 %\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)
2 \showgrid
3 %% Axes and Ticks %%
4 \myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax)
5 %% Graphical Objects %%
6 \psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)}
7 \fileplot{plotData.txt}
8 \endpsclip
9 \SpecialCoor
10 \rput[lt](!\xmax\space\xmin\space sub 15 div
11 \ymax\space\ymax\space\ymin\space sub 25 div sub){$y=\sin x$}
12 \NormalCoor
13 %\end{pspicture}
y = sin x
22
4. Several examples from geometry.
D
C
A B
E
80◦
30◦
A80◦
B
C
77◦
40◦
DE
53◦50◦60◦
A
B
C
P
T V
R
E
23
5. A few exotic tricks.
(a) A vector field.
−2 −1 1 2
−2
−1
1
2
24
(b) An ice-cream cone.
x
y
z
x
y
z
x y
z
25
(c) A level surface.
R
S
f(x, y, z) = c
b
b
∆σk
∆Pk
∆Ak
p
p∇f (xk, yk, zk)
ukvk
26
Figure 20: Fractals - Sierpinski Triangle
x
y
z
Figure 21: Sphere
The equation of a sphere with radius r centered at the origin is
x2 + y2 + z2 = r2
27
0
80
160
−80
−160
20 · 103 40 · 103 60 · 103 80 · 103 100 · 103
x
y
Figure 22: Brownian Motion
1
2
3
4
−1
−2
1 2 3 4−1−2−3−4−5
Figure 23: Not Sure What to Call This
28
Figure 24: Tessellations?
3
.141
59 26535
897
9323846264
3383279502884
19716
9399
375105820974944592
3078164062862089986
2803
482534
2117
0679821480865132823066
470
9384460955058223172535940
8128
4811
174
502
841
0270
193852110555964462294895493
038
1964
428
81097566593344612847564823378
6783
1652
7120190
9145
6485
66
92346034861045432664821339360726024
9141
2737
24587006606315588174881520920962829
25
4091
7153
643
678
9259
03600
1133
0530
54882046652138414695194151160943305727
03657
59591
953092186117381932611793105118548074462379
96274
9567
3518
8575
2724891
227
938
1830
1194
9129
83367336244065664308602139494639522473719070
217986
09437
02770539217176293176752384674818467669405132000
56812
7145
2635
60827
785
771
342
757
789
609
1736
3717
87214
6844090122495343014654958537105079227968925892354201
995611212
90219608640344181598136297747713099605187072113499999983
7297
8049
9510
59731
732
8160963
185
9502
445
9455
3469
0830
2642
522308253344685035261931188171010003137838752886587533208
38142061717
76691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959
Figure 25: π Spiral
30
Transparency Effects
The sketch below shows the infinite plane x = 0.
xy
z
xy
z
x = 0
In a similar manner one can sketch the graphs of the equations y = 0 and z = 0.
x
y
z
x
y
z
x = 0y =0
z =0
Notice that these three planes break up three-space into eight octants. The first octant coincides withpositive x, y and z-coordinates and is three-dimensional analogue of quadrant I in the plane.
31
A Saddle Point
x
y
z
x
y
z
32
Example 1. A Familiar Curve
Find the areas of the shaded regions.
r1 = 2 cos θ − sin θ
r2 = cos θ
1 2
−1
1
Pb
We first need to find the polar coordinates of pointof intersection, P . Setting r1 = r2 and solving we seethat θ = π/4. It follows that the area of green portionof the shaded region is given by
AG =1
2
∫ π/4
0
(
r21 − r2
2
)
dθ
It follows that
AG =1
2
∫ π/4
0
sin2 θ + 3 cos2 θ − 4 sin θ cos θ dθ
=1
2
∫ π/4
0
1 + 2 cos2 θ − 2 sin 2θ dθ
=1
2
∫ π/4
0
2 + cos 2θ − 2 sin 2θ dθ
=1
4(4θ + sin 2θ + 2 cos 2θ)
π/4
0
=1
4{(π + 1 + 0) − (0 + 0 + 2)} =
π − 1
4
Notice that
AG + AB =1
2
∫
arctan 2
0
r21 dθ
(Compare this last equation to the gas tank problem.)
Finally, can you find AY?
33
Definition. The Gamma Function
Γ(x) =
∫
∞
0
tx−1e−t dt (1)
Here the (improper) integral converges absolutely for all x ∈ R except for the non-positive integers. Infact, the Gamma function can be extended throughout the complex plane (again, except for thenon-positive integers).
y = Γ(x)
b b b
b
b
b
−4 −3 −2 −1 1 2 3 4 5
2
6
24
Observe that
Γ(1) =
∫
∞
0
t0e−t dt
=−1
et
∞
0
= 0 − (−1) = 1
and for positive integers n, integration by parts yields the recursive relation
Γ(n + 1) =
∫
∞
0
tne−t dt
= −tne−t
∞
0
+ n
∫
∞
0
tn−1e−t dt
= 0 + nΓ(n)
and Euler had found his extension. That is, for each nonnegative integer n, he could now define thefactorial by
n! = Γ(n + 1) (2)
34
Sketch the curve given by the equation below in polar coordinates.
r1 = f(θ) = 2 cos θ − sin θ, 0 ≤ θ ≤ π (3)
−2 −1 1 2
−1
1
m = tan(arctan 2) = 2
r1 = 2 cos θ − sin θ, 0 ≤ θ ≤ π
b
rθ-Coordinate System
1 2 3 4 5 6
−2
−1
1
2 r = f(θ)
This busy sketch requires some explanation. Recall that the given (polar) equationdefines a circle of radius
√5/2 centered at (1, −1/2). The blue part of circle identifies
that portion of polar equation r1 = 2 cos θ−sin θ, 0 ≤ θ ≤ arctan 2, i.e., when r1 ≥ 0.The red part identifies the part of the curve for arctan 2 ≤ θ ≤ π, i.e., when r1 < 0.
The yellow portion is actually the sketch of the curve
r2 = |f(θ)|, arctan 2 ≤ θ ≤ π (4)
The vectors (arrows) trace out the curve r2 for 0 ≤ θ ≤ 2π. Notice that the equationin (4) yields two circles which are symmetric about the line y = 2x (shown in green).
35
Top Related