Sci­en­tific Graph­ics Vi­su­al­i­sa­tion: An In­tro­duc­tion to PGF/TikZ

This is the sec­ond ar­ti­cle in a three-part se­ries on sci­en­tific graph­ics vi­su­al­i­sa­tion. It cov­ers PGF/TikZ soft­ware, which is free and open source. It also touches upon graph­ics file for­mats, La­TeX and PSTricks.

OpenSource For You - - Contents - By: Deepu Ben­son The au­thor is a free soft­ware en­thu­si­ast and his area of in­ter­est is the­o­ret­i­cal com­puter science. He main­tains a tech­ni­cal blog at­put­ing­for­be­gin­ and can be reached at deep­umb@hot­

In the first part on this se­ries on sci­en­tific graph­ics vi­su­al­i­sa­tion, we dis­cussed Mat­plotlib, a plot­ting util­ity for Python. In this ar­ti­cle, we will dis­cuss PGF/TikZ, a pair of lan­guages used for cre­at­ing vec­tor graph­ics. Maybe it is time to dis­cuss, in de­tail, the dif­fer­ences be­tween vec­tor graph­ics and raster graph­ics.

Raster graphic images are made of pix­els, which are the smallest el­e­ment in a dis­play de­vice. If you zoom your raster im­age in­def­i­nitely, then at some point you will start see­ing a lot of tiny dots. The qual­ity of the im­age goes down as you keep zoom­ing fur­ther. Some of the com­mon raster im­age for­mats in­clude JPEG, TIFF, GIF, BMP, PNG, etc. Vec­tor images, on the other hand, are drawn with the help of vec­tor soft­ware, with lines and shapes. The vec­tor graphic im­age will al­ways look the same, even when zoomed to very large sizes. Some of the pop­u­lar vec­tor graph­ics for­mats in­clude AI (Adobe Il­lus­tra­tor), EPS (En­cap­su­lated Post­Script), SVG (Scal­able Vec­tor Graph­ics), etc. Due to the high qual­ity of the images, it is al­ways bet­ter to use vec­tor graph­ics over raster graph­ics for tech­ni­cal di­a­grams.

A brief in­tro­duc­tion to La­TeX

Though PGF/TikZ can be used with Con­TeXt and the orig­i­nal TeX, it is most ex­ten­sively used with La­TeX. So, a brief in­tro­duc­tion to La­TeX is ab­so­lutely es­sen­tial be­fore pro­ceed­ing with PGF/TikZ. Due to this close re­la­tion­ship be­tween the two, PGF/TikZ can be con­sid­ered as a La­TeX pack­age for pro­gram­ming graph­ics. La­TeX is a very pop­u­lar cross-plat­form doc­u­ment-prepa­ra­tion sys­tem. It is free and open source soft­ware li­censed un­der the La­TeX Project Pub­lic Li­cense (LPPL). La­TeX was de­vel­oped by Les­lie Lam­port. It is based on TeX, a type­set­ting sys­tem de­vel­oped by Don­ald Knuth.

Very of­ten peo­ple con­sider La­TeX and TeX as one and the same, but this is not true. The fun­da­men­tal dif­fer­ence be­tween the two can be un­der­stood with the fol­low­ing ex­am­ple. Con­sider TeX as a pro­gram­ming lan­guage with no built-in func­tions and La­TeX as an ex­ten­sion to this lan­guage con­tain­ing a lot of built-in func­tions. Gen­er­ally, we can say that TeX is far more dif­fi­cult to learn and use when com­pared with La­TeX. A TeX dis­tri­bu­tion such as TeX Live is of­ten used in the Linux en­vi­ron­ment to ob­tain the ser­vices of La­TeX. While pre­par­ing doc­u­ments with La­TeX, com­mands are used in­stead of for­mat­ting the text to get spe­cial ef­fects like bold, ital­ics, etc. For ex­am­ple, in word pro­cess­ing pack­ages like Li­breOf­fice Writer or Mi­crosoft Word, you will see text in bold or ital­ics; whereas in a La­TeX file you will only see com­mands like \textbf or \tex­tit to pro­vide the same

ef­fect. Af­ter pro­cess­ing this La­TeX file, you will get an out­put doc­u­ment, which will show the for­mat­ted text.

Usu­ally, on ex­e­cu­tion, La­TeX files pro­duce PDF

(Portable Doc­u­ment For­mat) or DVI (de­vice in­de­pen­dent file for­mat) files as out­put. Con­sider the sim­ple La­TeX script ‘Hello.tex’ shown below, con­tain­ing only the ab­so­lutely es­sen­tial fea­tures of La­TeX. This La­TeX script and all the other PGF/TikZ scripts dis­cussed in this ar­ti­cle can be down­loaded from open­source­­ti­cle_­source_­code/ May18­graph­icsvi­su­al­i­sa­

\doc­u­ment­class{ar­ti­cle} \be­gin{doc­u­ment}

\textbf{\tex­tit{Hello World}} \end{doc­u­ment}

From the name Hello.tex it­self it is clear that the ex­ten­sion of a La­TeX file is tex. We use this La­TeX file as a tem­plate for ex­e­cut­ing all the PGF/TikZ code dis­cussed in this ar­ti­cle. First, let us go through this min­i­mal La­TeX ex­am­ple, line by line. The line of code \doc­u­ment­class{ar­ti­cle} de­fines the doc­u­ment class as an ar­ti­cle. Some other doc­u­ment classes pro­vided by La­TeX in­clude let­ter, book, re­port, beamer, etc. I be­lieve that ex­cept for the doc­u­ment class beamer, which is used to cre­ate pre­sen­ta­tions us­ing La­TeX, the pur­pose of all the other doc­u­ment classes men­tioned here is clear from their names it­self. The lines of code \be­gin{doc­u­ment} and \end{doc­u­ment} de­fine the area in which the ac­tual data of the out­put doc­u­ment can be given. In this case, we only have one line of code in the con­tent part of the La­TeX doc­u­ment, \textbf{\tex­tit{Hello World}}. This line tells the La­TeX in­ter­preter to print the text ‘Hello World’ in bold and ital­ics.

So, now we have a La­TeX file ready with us to be ex­e­cuted, but what is the best way to process it? There are dif­fer­ent ways to process La­TeX files. For ex­am­ple, you can use Over­leaf, a col­lab­o­ra­tive writ­ing and pub­lish­ing sys­tem that can process La­TeX code. But, in this ar­ti­cle, I will be ex­plor­ing two other meth­ods to process La­TeX.

First, let’s ex­e­cute the La­TeX in­ter­preter from the ter­mi­nal. Open a ter­mi­nal in the di­rec­tory con­tain­ing the La­TeX file Hello.tex and ex­e­cute the com­mand la­tex Hello.tex. On ex­e­cu­tion, the La­TeX file will pro­duce a doc­u­ment called Hello.dvi with the text ‘Hello World’ printed in bold and ital­ics. The de­fault out­put for­mat of La­TeX is DVI. If you want the out­put file in PDF for­mat, ex­e­cute the fol­low­ing com­mand on the ter­mi­nal pdfla­tex Hello.tex, which will use an ex­ten­sion of La­TeX called pdfLa­TeX to pro­duce the out­put file Hello.pdf with the same con­tent as the other out­put file Hello.dvi.

The sec­ond method is to use a La­TeX ed­i­tor like Tex­maker, a pop­u­lar free and open source cross-plat­form La­TeX ed­i­tor with an in­te­grated PDF and DVI viewer. Open the La­TeX file Hello.tex in Tex­maker and, in the menu, you will find Tools>La­TeX and Tools>PDFLa­TeX to ex­e­cute La­TeX and its ex­ten­sion pdfLa­TeX. Whether you use the tool La­TeX, pdfLa­TeX or Tex­maker, the for­mat­ted text in the out­put doc­u­ment will be the same. Even though Tex­maker has the built-in op­tion to view PDF and DVI out­put files, make sure that your sys­tem has a doc­u­ment viewer like Oku­lar that is ca­pa­ble of dis­play­ing DVI and PDF files so that the doc­u­ments can be viewed di­rectly. There are many other La­TeX ed­i­tors like TeXs­tu­dio, TeX­works, Kile, etc. Us­ing Tex­maker is just a per­sonal choice, and I en­cour­age you to try out any of the other La­TeX ed­i­tors that are avail­able and then stick with the one you like the most. Also, re­mem­ber that some­times you need to process the La­TeX file mul­ti­ple times to ob­tain the cor­rect la­bels, bib­li­og­ra­phy, in­dex, etc.

One prob­lem that of­ten con­fuses new users of La­TeX is the large num­ber of sup­port­ing files gen­er­ated by it. If you ob­serve the di­rec­tory con­tain­ing the file Hello.tex, you will see files called Hello.aux and Hello.log, apart from the out­put files Hello.pdf and Hello.dvi. And as your La­TeX doc­u­ment be­comes more and more com­plex, the num­ber of such files cre­ated also in­creases. I am not go­ing to ex­plain the pur­pose of these sup­port­ing files in this ar­ti­cle, but you don’t need to worry be­cause out of the large num­ber of files cre­ated, you only need to worry about the La­TeX file with the ex­ten­sion tex and the out­put files with ex­ten­sions pdf and dvi. All other files can be re­gen­er­ated by ex­e­cut­ing the La­TeX in­ter­preter.

An in­tro­duc­tion to PGF/TikZ

Now that we are fa­mil­iar with how La­TeX works, let us talk about PGF/TikZ, which was de­vel­oped by Till Tan­tau, us­ing the soft­ware, TeX. As men­tioned ear­lier, it is not a sin­gle tool but two sep­a­rate lan­guages paired to­gether to pro­duce high qual­ity vec­tor graph­ics. PGF is the lower-level lan­guage and TikZ is a set of higher-level macros that use PGF. The re­la­tion­ship be­tween PGF and TikZ is some­what sim­i­lar to the re­la­tion­ship be­tween TeX and La­TeX, the for­mer stat­ing the ba­sic syn­tax and the lat­ter pro­vid­ing macros for ease of use.

TikZ was first in­tro­duced with ver­sion 0.95 of PGF. The lat­est ver­sion of PGF/TikZ is 3.0.1 re­leased in Au­gust 2015. PGF is the acro­nym for ‘portable graph­ics for­mat’. TikZ is a re­cur­sive acro­nym for ‘TikZ ist kein Ze­ichen­pro­gramm’, Ger­man for ‘TikZ is not a draw­ing pro­gram’ — as­sert­ing the fact that these are pro­gram­ming lan­guages ca­pa­ble of pow­er­ful func­tions. Un­like the other pop­u­lar graph­ics vi­su­al­i­sa­tion tool called PSTricks, which uses a syn­tax re­sem­bling Post­Script, PGF and TikZ de­scribe the images to be drawn by us­ing a syn­tax that re­sem­bles Me­taPost, a lan­guage that is used to pro­duce vec­tor graphic di­a­grams.

This over-de­pen­dence of PSTricks on Post­Script is an ad­van­tage and dis­ad­van­tage at the same time. The dis­ad­van­tages of PSTricks in­clude the lim­ited out­put for­mats it of­fers (PSTricks can only pro­duce Post­Script out­put and not PDF out­put) and in­com­pat­i­bil­ity with some as­so­ci­ated tools of La­TeX like pdfTeX. But PGF/TikZ is able to pro­duce both Post­Script and PDF out­put and has a high level of

com­pat­i­bil­ity with all the tools as­so­ci­ated with La­TeX, which makes some knowl­edge of PGF/TikZ very es­sen­tial.

A sim­ple PGF/TikZ ex­am­ple

PGF/TikZ pro­duces vec­tor graph­ics from a geo­met­ric de­scrip­tion of the im­age to be drawn by us­ing its own set of in­struc­tions. Be­fore ex­plor­ing the code any fur­ther, let us dis­cuss two im­por­tant as­pects of PGF/TikZ, which are points and paths. Points refer to a spe­cific lo­ca­tion in a two-di­men­sional plane. Points can be spec­i­fied as Carte­sian co­or­di­nates, po­lar co­or­di­nates, named points and rel­a­tive points in PGF/TikZ. To make our dis­cus­sion rel­a­tively sim­ple and less math­e­mat­i­cal, we will only dis­cuss the points be­ing de­scribed as Carte­sian co­or­di­nates. For ex­am­ple, the Carte­sian co­or­di­nates (p, q) refer to a point lo­cated at p units in the direc­tion of the x-axis and q units in the direc­tion of the y-axis. For ease of un­der­stand­ing, the ori­gin denoted by (0,0) can be con­sid­ered as lo­cated at the bot­tom-left corner of the plane when dis­played on the screen.

The other im­por­tant as­pect of PGF/TikZ is how a path is traced in a two-di­men­sional plane. This as­pect of tracing paths in PGF/TikZ is ex­plained with the fol­low­ing ex­am­ple scripts. Let us start with a sim­ple ex­am­ple in­volv­ing PGF/TikZ code to un­der­stand how paths are spec­i­fied. Con­sider the La­TeX script pgf1.tex shown below, which draws two rec­tan­gles. As stated ear­lier, the PGF/TikZ code is in­cor­po­rated in­side the min­i­mal La­TeX tem­plate men­tioned ear­lier.





\draw (1,1)--(2,1)--(2,3)--(1,3)--cy­cle; \draw (4,4)rec­tan­gle(5,6); \end{tikzpic­ture}


Now let us go through the code in the file pgf1.tex, line-by-line, to un­der­stand it bet­ter. I will only ex­plain the lines of code newly in­tro­duced in this script. The line of code \usep­a­ck­age{tikz} makes sure that La­TeX can use all the func­tion­al­i­ties of the pack­age TikZ. The lines of code \be­gin{tikzpic­ture} and \end{tikzpic­ture} de­note the en­vi­ron­ment in­side which PGF/TikZ code can be en­tered to draw images. The line of code \draw (1,1)--(2,1)--(2,3)--(1,3)--cy­cle; draws four lines in the two-di­men­sional plane by us­ing the draw com­mand. The first line is drawn from point (1,1) to point (2,1), the sec­ond line is drawn from point (2,1) to point (2,3), the third line is drawn from point (2,3) to point (1,3), and the fourth line is drawn from point (1,3) to point (1,1). The por­tion of the code that is re­spon­si­ble for draw­ing the fourth line is (1,3)--cy­cle; which will com­plete the rec­tan­gle by draw­ing a line from point (1,3) to the first point used in this draw com­mand, which is point (1,1).

The line of code \draw (4,4)rec­tan­gle(5,6); draws a rec­tan­gle by pro­vid­ing the lo­ca­tion of the bot­tom-left and top-right cor­ners of the rec­tan­gle. In this case, the points are (4,4) and (5,6), re­spec­tively which rep­re­sent these two cor­ners. Please note the fact that PGF/

TikZ com­mands are ter­mi­nated with a semi­colon (;), fail­ing which they will lead to an er­ror. Now let us ex­e­cute this script to view the im­age drawn. This La­TeX script can also be ex­e­cuted like any other or­di­nary La­TeX doc­u­ment — ei­ther use the com­mand pdfla­tex or la­tex on a ter­mi­nal or use Tex­maker. I have used the com­mand pdfla­tex pgf1.tex on the ter­mi­nal to pro­duce the out­put file pgf1.pdf. Fig­ure 1 shows the im­age in the doc­u­ment pgf1.pdf.

Coloured images with PGF/TikZ

It is very easy to draw coloured images with PGF/TikZ. Con­sider the script pgf2.tex given below. In this script, three tri­an­gles are drawn in red, green and blue.





\draw[fill=red] (0,1)--(2,1)--(1,3)--cy­cle; \draw[fill=green] (3,1)--(5,1)--(4,3)--cy­cle; \draw[fill=blue] (6,1)--(8,1)--(7,3)--cy­cle; \end{tikzpic­ture}


The only line of code that needs an ex­pla­na­tion is \draw[fill=red] (0,1)--(2,1)--(1,3)--cy­cle;. This line draws a tri­an­gle by draw­ing three lines. The first line is drawn from point (0,1) to point (2,1), the sec­ond line is drawn from point (2,1) to point (1,3), and the third line is drawn from point (1,3) to point (0,1), thus form­ing a tri­an­gle. The colour to be filled in­side the tri­an­gle is pro­vided as an op­tion to the draw com­mand. The op­tion to fill the tri­an­gle with red colour is given by the code [fill=red]. The re­main­ing two lines in the tikzpic­ture en­vi­ron­ment of La­TeX draw two more tri­an­gles, and fill them with green and blue. On ex­e­cut­ing the com­mand pdfla­tex pgf2.tex, an out­put file called pgf2.pdf will be gen­er­ated. Fig­ure 2 shows the im­age in the doc­u­ment pgf2.pdf.

There are other op­tions also avail­able with the draw

com­mand. For ex­am­ple, there are op­tions to change the colour of the line from the de­fault black; to vary the thick­ness of the line be­ing drawn, etc. Re­place the three lines of code in­side the tikzpic­ture en­vi­ron­ment of the script pgf2.tex with the lines of code \draw[yel­low, very thick, fill=red] (0,1)--(2,1)--(1,3)--cy­cle;, \draw[yel­low, very thick, fill=green] (3,1)--(5,1)--(4,3)--cy­cle; and \draw[yel­low, very thick, fill=blue] (6,1)--(8,1)--(7,3)--cy­cle; to ob­tain pgf3.tex. On ex­e­cut­ing the com­mand, pdfla­tex pgf3.tex, this script will pro­duce an out­put doc­u­ment named pgf3.pdf, which has three tri­an­gles drawn with thick yel­low coloured lines and filled with red, green and blue colour. The script pgf3.tex is also avail­able for down­load.

Draw­ing cir­cles with PGF/TikZ

Now let us look at how to draw cir­cles us­ing PGF/TikZ. Con­sider the script pgf4.tex shown below.





\draw[fill=red] (0,0) cir­cle (4cm); \draw[fill=green] (0,0) cir­cle (3cm); \draw[fill=blue] (0,0) cir­cle (2cm); \draw[fill=or­ange] (0,0) cir­cle (1cm); \end{tikzpic­ture}


The only line of code that re­quires an ex­pla­na­tion is \draw[fill=red] (0,0) cir­cle (4cm);. This line draws a red cir­cle of ra­dius 4cm with its cen­tre at point (0, 0) and fills this cir­cle with red colour. The re­main­ing three lines in the tikzpic­ture en­vi­ron­ment of La­TeX draw three more cir­cles with a ra­dius of 1cm less than the pre­vi­ous one and with the cen­tre at the same point, so that we have four con­cen­tric cir­cles drawn in the fi­nal out­put file. On ex­e­cut­ing the com­mand pdfla­tex pgf4.tex in a ter­mi­nal, four con­cen­tric cir­cles are drawn in red, green, blue and or­ange colours. Fig­ure 3 shows the out­put of the script pgf4.tex.

Re­mem­ber that com­po­nents of an im­age with mul­ti­ple lay­ers are drawn in the or­der in which the line of code cor­re­spond­ing to a par­tic­u­lar com­po­nent ap­pears in the tikzpic­ture en­vi­ron­ment of La­TeX. In the pre­vi­ous ex­am­ple (pgf4.tex), the red cir­cle with a ra­dius of 4cm is drawn first, then the green cir­cle with a ra­dius of 3cm, fol­lowed by the blue cir­cle with a ra­dius of 2cm and fi­nally the or­ange cir­cle with a ra­dius of 1cm. For a bet­ter un­der­stand­ing, let us mod­ify the script pgf4.tex in such a way that the cir­cles are drawn in the re­verse or­der — the smallest cir­cle is drawn first and so on — to ob­tain pgf5.tex. Now, what will be the im­age drawn in the out­put doc­u­ment pgf5.pdf when this mod­i­fied La­TeX file pgf5.tex (shown below) is ex­e­cuted with the com­mand pdfla­tex pgf5.tex?





\draw[fill=or­ange] (0,0) cir­cle (1cm); \draw[fill=blue] (0,0) cir­cle (2cm); \draw[fill=green] (0,0) cir­cle (3cm); \draw[fill=red] (0,0) cir­cle (4cm); \end{tikzpic­ture}


You might be a bit sur­prised to see that a sin­gle red cir­cle with a ra­dius of 4cm alone is drawn in the out­put file pgf5.pdf. I as­sure you, we didn’t do any­thing wrong. It’s just the way PGF/TikZ works. Try to find out the rea­son for this ab­nor­mal be­hav­iour. If you are un­able to find an an­swer, I have added it as a com­ment in the file pgf5.tex avail­able for down­load.

Loops in PGF/TikZ

So far, we have drawn two rec­tan­gles, three tri­an­gles and four cir­cles. What hap­pens if we are asked to draw a hun­dred tri­an­gles or a thou­sand cir­cles? Well, that’s why we have loops in PGF/TikZ to help us. PGF/TikZ has many ef­fi­cient loop­ing and con­trol struc­tures to help us draw a large num­ber of images with rel­a­tive ease. Con­sider the ex­am­ple script pgf6.tex shown below, which uses the fore­ach loop pro­vided by PGF/TikZ.





\fore­ach \x in {1,2,...,9} {

\fore­ach \y in {1,2,3} { \draw[fill=red!\x\y!green] (\x,\y) cir­cle (4mm);


} \end{tikzpic­ture} \end{doc­u­ment}

The line of code \fore­ach \x in {1,2,...,9} { de­fines an outer loop that it­er­ates nine times. The line of code \fore­ach \y in {1,2,3} { de­fines an in­ner loop that it­er­ates three times. Thus the line of code \draw[fill=red!\x0!green] (\x,\y) cir­cle

(4mm); in­side the in­ner loop gets ex­e­cuted for a to­tal of 27 times and, there­fore, draws 27 cir­cles that each have a ra­dius of 4mm. The cen­tres of these cir­cles are de­fined by the code frag­ment (\x \y). There­fore, the cen­tres are not fixed -- they are the points (1,1), (1,2), (1,3), (2,1), (2,2), (2,3), …, (9,1), (9,2) and (9,3), a to­tal of 27 points in the two-di­men­sional plane as the val­ues of vari­ables x and y change in­side the outer and in­ner loops.

The code frag­ment [fill=red!\x\y!green] de­fines the colour filled in­side the cir­cles. The code frag­ment red!40!green de­fines a cir­cle that has 40 per cent red and the re­main­ing 60 per cent green. So, in this case, since the val­ues of the vari­ables x and y change in­side the loops, no two cir­cles will have the same colour. But it may not be pos­si­ble to iden­tify the dif­fer­ence in colour be­tween a cir­cle hav­ing 11 per cent red and 89 per cent green, and an­other cir­cle with 12 per cent red and 88 per cent green. That is the rea­son why some of the ad­ja­cent cir­cles may look sim­i­lar in colour. On ex­e­cut­ing the com­mand pdfla­tex pgf6.tex the La­TeX file pgf6. tex will pro­duce an out­put file ti­tled pgf6.pdf with the im­age shown in Fig­ure 4.

Let us change just a sin­gle line of code in the file pgf6.tex to ob­tain pgf7.tex. The line of code \fore­ach \y in {1,2,3} { in pgf6.tex is re­placed with the line \fore­ach \y in {1,2,...,12} { in pgf7.tex. On ex­e­cut­ing the file pgf7. tex with the com­mand pdfla­tex pgf7.tex, you will get an out­put file ti­tled pgf7.pdf with the im­age shown in Fig­ure 5. A few char­ac­ters are added to a sin­gle line of code and the im­age changes dras­ti­cally. I be­lieve this ex­am­ple clearly il­lus­trates the ben­e­fit of us­ing graph­i­cal pro­gram­ming tools like PGF/TikZ and PSTricks rather than con­ven­tional im­age de­sign soft­ware. Imag­ine how much time it would take to draw a tech­ni­cal di­a­gram sim­i­lar to the one we have dis­cussed, with a lot of im­age com­po­nents placed at spe­cific lo­ca­tions, if we had used typ­i­cal im­age de­sign soft­ware.

Now it is time to wind up our dis­cus­sion. You should now be able to write and ex­e­cute La­TeX scripts em­bed­ded with PGF/TikZ scripts to pro­duce a DVI or a PDF file as out­put, ei­ther by us­ing La­TeX or pdfLa­TeX in the ter­mi­nal or by us­ing the pop­u­lar La­TeX ed­i­tor Tex­maker. We have left out a few im­por­tant top­ics like three­d­i­men­sional plot­ting, plot­ting in the beamer doc­u­ment class of La­TeX, etc, but the in­tro­duc­tion given in this ar­ti­cle will def­i­nitely pro­vide you with a head start over oth­ers. In my opin­ion, PGF/TikZ is a pow­er­ful weapon in the hands of pro­fes­sion­als who need to pro­duce good qual­ity tech­ni­cal di­a­grams.

Why learn PSTricks?

PSTricks is yet an­other pow­er­ful sci­en­tific graph­ics vi­su­al­i­sa­tion tool used along with La­TeX. One last ques­tion I want to an­swer be­fore con­clud­ing this ar­ti­cle is, ‘Why learn PSTricks if PGF/TikZ is so great?’ Well, PGF/TikZ is def­i­nitely a great tool but PSTricks also has some­thing good to of­fer. As men­tioned ear­lier, PSTricks is as­so­ci­ated with Post­Script, a very pow­er­ful page de­scrip­tion lan­guage. The pro­gram­ming power of­fered by Post­Script makes it ab­so­lutely es­sen­tial that I should also in­tro­duce PSTricks, so that po­ten­tial users can ex­per­i­ment with both PGF/TikZ as well as PSTricks, and then make an in­formed de­ci­sion re­gard­ing their choice for a good vi­su­al­i­sa­tion tool for La­TeX. So, in the next and fi­nal part of this se­ries on sci­en­tific graph­ics vi­su­al­i­sa­tion, we will dis­cuss PSTricks.

Fig­ure 1: Two rec­tan­gles drawn with PGF/TikZ

Fig­ure 2: Three coloured tri­an­gles drawn with PGF/TikZ

Fig­ure 3: Four coloured con­cen­tric cir­cles drawn with PGF/TikZ

Fig­ure 4: Out­put of pgf6.tex

Fig­ure 5: Out­put of pgf7.tex

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.