0% found this document useful (0 votes)
78 views14 pages

PSTricksLecture Summer 2011

The document provides examples of creating graphics in LaTeX using PSTricks. It includes: 1) Examples of basic graphics objects like lines, curves, circles, ellipses, and functions plotted between predefined limits. 2) Code for plotting data from an external file and customizing axes. 3) Several examples from geometry like vectors and 3D surfaces.

Uploaded by

RafaelOlivoD
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views14 pages

PSTricksLecture Summer 2011

The document provides examples of creating graphics in LaTeX using PSTricks. It includes: 1) Examples of basic graphics objects like lines, curves, circles, ellipses, and functions plotted between predefined limits. 2) Code for plotting data from an external file and customizing axes. 3) Several examples from geometry like vectors and 3D surfaces.

Uploaded by

RafaelOlivoD
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

A L TEX Graphics with PSTricks

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

Figure 1: Graphing simple functions.

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

Figure 2: Graphing with some fancy eects.

r = 1 + 2 sin
3

x-y Coordinate System

(c)
1

12 Figure 3: Polar Graphs

1 P (2, 6)

(b)

(a)

Figure 4: Area between two curves.

v u u+v v
y

r = g2 () r=a =

c = 0.01 c = 0.025 c = 0.05 c = 0.075 c = 0. 1 c = 0.11 c = 0.125

xy = c

P0
1

r = g1 ()

Figure 5: Lagrange Multipliers

z z

x Figure 7: Surface Integrals

x C y
1

Figure 6: Exposed Solid z

Increasing Vector Magnitude

x 9 10

3. PSTricks To use PSTricks you must include the following lines in the preamble of your document.

(a) Preliminaries A simple line.


1

1 2 3 4 5 6 7

\usepackage{pst-eucl} \usepackage{calc} \usepackage{pst-3dplot}% \usepackage{pst-grad} \usepackage{pst-plot,pst-math,pstricks-add}% \usepackage{pst-all} %\RequirePackage{pst-xkey}

2 3

\begin{pspicture}(-6,-6)(6,6) \psline[linecolor=blue,linewidth=1.5pt](-3,1)(2,2) \end{pspicture}

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

Here the command \showgrid is a custom macro dened below.


1 2 3 4 5 6 7 8

\newpsobject{showgrid}{psgrid}{% gridlabels=0pt% ,griddots=0% ,gridwidth=0.5pt% ,gridcolor=gray% ,subgriddiv=0% ,subgridwidth=0.25pt% ,subgridcolor=red}

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}

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \showgrid \pscurve[linecolor=red,linewidth=1.5pt,showpoints=true]% (\xmin,1)(0,2)(3,1)(\xmax,\ymax) %\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

There are built-in shapes.


1 2 3 4 5 6 7 8 9

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}

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \showgrid \psellipse[linecolor=blue,linewidth=1.5pt] (1,0)(1,1.5) \psdots[linecolor=red,linewidth=1.25pt](0,0) \SpecialCoor \uput{6pt}[180](0,0){$(0,0)$} \NormalCoor %\end{pspicture}

1 2 3 4 5

(0, 0)

Here is the same object lled-in and clipped.


1 1 2 3 4 5 6 7

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) %\showgrid \psarc*[linecolor=red](0,0){1.5}{215}{0} \psarc[linecolor=blue ,showpoints=true](0,0){1.5}{215}{0} \psdots[linecolor=black,linewidth=1.5pt](0,0) %\end{pspicture}

2 3 4 5 6 7 8

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax) \showgrid \psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)} \pscircle*[linecolor=red,linewidth=1.5pt] (-2,-1){2} \endpsclip \pswedge*[linecolor=white](-2,-1){1}{15}{105} %\end{pspicture}

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

Here is a trig function.

y = cos x

17

18

Heres something useful for integration theory


1

Here is the code y= 1 x


1 2 3 4 5 6 7 8 9 10 11 12

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

0 0.06279 0.12533 ...

%\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

4. Several examples from geometry.

5. A few exotic tricks. (a) A vector eld.

A 30 80 E

C D
1

80 60 50

40 77

53

P T R A C

23

24

(b) A three dimensional wedge.

(c) An ice-cream cone.

y y x x

25

26

z (d) A level surface.

f (x, y, z ) = c

f (xk , yk , zk )

Pk

vk

uk k

Ak

27

28

You might also like