
Graphics, in particular plotting data Alan BRASLAU Service de physique de l’état condensé, CEA/Saclay, France Bassange – 20/09/2011 Why pay taxes? 3D graphics are sexy! Graphics, in particular plotting data 2 1. External graphics Produced using your favorite external program… Usage: \externalfigure [filename][option=val] file formats: pdf, mps, jpg jpeg, jp2, png, jbig jbig2 jb2, j j j svg svgz, eps, ai, gif, tif tiff, mov, flv, mp4, (but not avi), j j tex, cld, … automatically converted using external programs such as ghostscript, imageMagick, graphicsMagick, inkscape, etc. (if available). advantage: use of your tried and true external programs that you know and love… disadvantage: poor control of style, fonts, font size, colors, line weights, etc.; possible/probable inconsistencies between figures. Graphics, in particular plotting data 3 2. TEX-friendly graphics A. ‘external’ programs (or macros) METAPOST PSTricks, PiCTeX, TikZ, matplotlib (python), asymptote, R, gnuplot, … More or less well integrated in ConTEXt; more or less TEX-friendly. METAPOST B. MetaFun: graphics well integrated in ConTEXt Usage: \startMPcode … \stopMPcode \startuseMPgraphic{label} … \stopuseMPgraphic Graphics, in particular plotting data 4 http://www.pragma-ade.com/general/manuals/metafun-p.pdf Also available on paper, bound, for 49.00 € from www.h2o-books.com 375 pages. context mkiv Hans Hagen metafun Graphics, in particular plotting data 5 texlive/2011/texmf-dist/doc/metapost/base/mpman.pdf METAPOST a user’s manual John D. Hobby and the MetaPost development team documented version: 1.504 April 5, 2011 Graphics, in particular plotting data 6 TikZ (vs. MetaFun) TikZ (built upon PGF) is a METAPOST-inspired graphics language. More and more popular with LATEX users, it has always functioned well under ConTEXt. Its great strength is a & & PGF Z k very well written tutorial and TikZ PGF manual; it is rich in features Manual for Version 2.10 2.10 and has many extras (such as Manual for Version pgfplots, pgfgantt, tikz-3dplot, \begin{tikzpicture} \nodeshadowed [at={(-5,8 )},yslant=0.05] and more). coordinate front at Huge Ti textcolor orange emph k Z \ ( ) (0,0); {\ \ { }{\ { }} }; \coordinate (horizon) at (0,.31\paperheight); \nodeshadowed [at={( 0,8.3)}] \coordinate (bottom) at (0,-.6\paperheight); {\huge \textcolor{green!50!black!50}{\&}}; \coordinate (sky) at (0,.57\paperheight); \nodeshadowed [at={( 5,8 )},yslant=-0.05] \coordinate (left) at (-.51\paperwidth,0); {\Huge \textsc{PGF}}; \coordinate (right) at (.51\paperwidth,0); \nodeshadowed [at={( 0,5 )}] {Manual for Version \pgftypesetversion}; \shade [bottom color=white, top color=blue!30!black!50] \foreach \where in {-9cm,9cm}{ ([yshift=-5mm]horizon - j left) \nodeshadowed [at={(\where,5cm)}] { \tikz rectangle (sky - j right); \draw [green!20!black, rotate=90, l-system={rule set={F -> FF-[-F+F]+[+F-F]}, However, its syntax is more \shade [bottom color=black!70!green!25, axiom=F, order=4,step=2pt, top color=black!70!green!10] randomize step percent=50, angle=30, (front - j left) -- (horizon - j left) randomize angle percent=5}] l-system; }} decorate [decoration=random steps]{ -- (horizon - j right)} \foreach \i in {0.5,0.6,...,2} -- (front - j right) -- cycle; \fill in the spirit of L T X then [white,opacity=\i/2, A \shade [top color=black!70!green!25, decoration=Koch snowflake, E bottom color=black!25] shift=(horizon),shift={(rand∗11,rnd∗7)}, ([yshift=-5mm-1pt]front - j left) scale=\i,double copy shadow={ rectangle ([yshift=1pt]front - j right); opacity=0.2,shadow xshift=0pt, shadow yshift=3∗\i pt,fill=white,draw=none}] \fill [black!25] decorate { ConT Xt (although this (bottom - j left) decorate { E rectangle ([yshift=-5mm]front - j right); decorate { (0,0)- ++(60:1) -- ++(-60:1) -- cycle \def\nodeshadowed[#1]#2;{ } } }; \node[scale=2,above,#1]{ \global\setbox\mybox=\hbox{#2} \node (left text) ... judgment is purely subjective \copy\mybox}; \node (right text) ... \node[scale=2,above,#1,yscale=-1, scope fading=south,opacity=0.4]{\box\mybox}; \fill [decorate,decoration={footprints,foot of=gnome}, } opacity=.5,brown](rand∗8,-rnd∗10) to [out=rand∗180,in=rand∗180] (rand∗8,-rnd∗10); and personal). \end{tikzpicture} Graphics, in particular plotting data 7 TikZ has a loyal following TikZ remains active (on the ConTEXt mailing list as well). Bugs in TikZ (introduced as ConTEXt evolves) get fixed quickly. However, The core use of TikZ is LATEX, and so it must remain compatible with the many flavors of LATEX. Calculations can be very slow. For example: “PGFPLOTS’ three dimensional routines are slow. There are reasons for this and some of them may vanish in future versions. … Besides the speed limitations, three dimensional plots reach memory limits easily. Therefore, the plot complexity of three dimensional plots is limited to relatively coarse resolutions.” These limitations remain true for all TikZ graphics. (Could TikZ evolve towards lualatex, or must it remain compatible with all LATEX motors?) Graphics, in particular plotting data 8 MetaFun is in the core of ConTEXt So, why do we ever consider using anything else? METAPOST has a steep learning-curve; METAPOST, although pretty well-documented, is perhaps lacking a good tutorial; MetaFun and METAPOST have been extended through many higher-level macro packages (such as graph and the chart module, just to name two that I sometimes use). We need more, for example, convenient ways to manipulate common graphical representations (such as diagrams, trees, etc.). Graphics, in particular plotting data 9 Drawing diagrams Suggestion/question: could the \framed macro be extended to be used in a way that is similar to what is called a node in TikZ: 1. absolute or relative placement on a canvas; 2. enclosure (and typeset) inside an arbitrary, closed path; 3. connected by various lines or arrows (using anchor points?) How do we get \startCANVAS from here \frame [start][frame=circle,width=3cm, backgroundcolor=green,foregroundcolor=white] {How do we get from here} \frame [stop][frame=hexagon,width=3cm, location=start.lrt, backgroundcolor=red,foregroundcolor=white] {to here?} \drawarrow [from=start,to=stop] to here? \stopCANVAS Graphics, in particular plotting data 10 What about plotting data? METAPOST graph macros crystalline helium (John D. Hobby) (100) (101) 1.001 (102) \usemodule [graph] (110) 0 (112) Q 2D (‘xy’) plotting of data / 1 Q 0.999 METAPOST (< 2.0) uses fixed point arithmetic. Much (100) (101) of the complication of the 1.001 (102) (110) graph macros arises from (112) 0 handling floating-point d 1 numbers. / d limitations in plotting ! very small and vary large 0.999 quantities (as well as very 0 0.5 1 1.5 small increments). T (K) Graphics, in particular plotting data 11 Mlog arithmetic x 216 The graph macros represent numbers in “Mlog” form, that is as µ · 24 where µ = e2− : − “A number x in Mlog form represents exp(x) if x is an even multiple of " and exp(x) if x is an odd multiple of ", 16 − where " = 2− [ 1.53e-5] is the basic unit for METAPOST’s ≈ fixpoint numbers. Such numbers can represent values large as 3.8877e+55 or as small as 1.604e-28 (anything less than that is treated as zero).” METAPOST 2.0 promises arbitrary precision, floating-point arithmetic. The graph macros can be rewritten (and greatly simplified). What about using lua? Think about the possibilities (easily achieved…). Graphics, in particular plotting data 12 Limitations in handling real data Currently, all but the most trivial manipulations of numerical data must be processed outside of METAPOST. One of my favorite tools is awk (or gawk which adds a few useful extensions). Awk is a very flexible, yet simple and robust interpreted language, using C-like syntax. In many ways, it shares much in common with lua. Another route, quite popular today, is python. Python is at the basis of the matplotlib package, and this solution is found to be quite satisfactory by many. Matplotlib uses a MATLAB-like syntax. Graphics, in particular plotting data 13 What is needed: 2D plots barcharts/histograms piecharts polar diagrams ternary diagrams contour plots 3D plots 3D surfaces (In general, a 3D extension to METAPOST would be desirable.) Graphics, in particular plotting data 14 3D METAPOST A 3D METAPOST macro package was developed by Denis Roegel. It is distributed with TEXlive under mp3d (and on CTAN, of course). \startMPcode input 3dgeom ; drawing_scale := 10cm ; vardef def_C(expr inst) = new_obj_points(inst,9) ; set_C_points(inst) ; enddef ; vardef set_C_points(expr inst) = set_point(1)(0,0,0) ; set_point(2)(0,0,1) ; set_point(3)(0,1,0) ; set_point(4)(0,1,1) ; set_point(5)(1,0,0) ; set_point(6)(1,0,1) ; set_point(7)(1,1,0) ; set_point(8)(1,1,1) ; set_point(9)(.5,.5.,.5) ; enddef ; vardef draw_C(expr inst) = draw_lines(1,2,4,3,1) ; draw_lines(5,6,8,7,5) ; draw_line(1,5) ; draw_line(2,6) ; draw_line(3,7) ; draw_line(4,8) ; enddef ; assign_obj("cube","C"); for i:=0 upto 10: if (i > 0) : picture pic ; pic := currentpicture ; currentpicture := nullpicture ; draw pic xshifted 1.65cm ; fi set_point_(Obs)(20*cosd(7.2*i),20*sind(7.2*i),6) ; Obs_phi := 90 ; Obs_dist := 2 ; point_of_view_obj("cube",8,Obs_phi) ; draw_obj("cube") ; endfor; \stopMPcode Graphics, in particular plotting data 15 Examples Cubic crystal lattices c bcc fcc polyhedra – 3dpoly Graphics, in particular plotting data 16 3d, 3dgeom, 3dpoly Handles vectors and polyhedra; Spheres, cylinders, cones, etc., planned, but not yet implemented; Could objects be defined in terms of a few basic 3D primitives rather then simply as a collection of indices? Handles different projection systems or perspectives (linear, parallel, oblique); A unique, global triplet of arrays stores the constituent points of all objects. The allocation (and freeing) of storage is a bit awkward. This could (easily?) be improved with some internal housekeeping.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages24 Page
-
File Size-