Preparing Figures in Matlab and L A TEX for Quality Publications Azad Ghaffari Cymer Center for Control Systems and Dynamics - UC San Diego Second Edition, January 214
Image formats: Vector vs. Raster Raster graphics or bitmap Made up of individual pixels, resolution dependent Resizing reduces quality Minimal support for transparency Conversion to vector is difficult File types:.jpg,.gif,.tif, and.bmp Vector graphics or line art Created mathematically w/o the use of pixels High resolution Scalable to any size w/o pixelation or quality loss Conversion to raster is easy File types:.eps,.pdf,.ai, and.dxf Vector Raster
Figures in Matlab Handle Graphics is an object-oriented structure for creating, manipulating and displaying graphics Graphics objects: basic drawing elements used in Matlab to display graphs and GUI components Every graphics object: Unique identifier, called a handle Set of characteristics, called properties Possible to modify every single property using the command-line Objects organized into a hierarchy Root Figure UI Objects Axes Hidden Annotation Axes Core Objects Plot Objects Group Objects Annotation Objects
Avoid common mistakes Don t Use graphical commands with their default setting Export figures using the export menu function Modify figure properties using the mouse Use third party graphics editors where possible Do Use functions and scripts to generate plots: Reuseability Specify figure properties: Modifability Generate your figures using print command: Controllability
plot function Calling the plot function creates graphics objects: Figures: Windows that contain axes toolbars, menus, etc. Axes: Frames that contain graphs Lineseries plot objects: Representations of data passed to the plot function Text: Labels for axes tick marks, optional titles and annotations Main functions for working with objects gcf Handle of the current figure gca Handle of the current axis in the current figure get Query the values of an object s properties set Set the values of an object s properties delet Delete an object copyobj Copy graphics object
Example t = :.1:4*pi; y = sin(t); plot(t,y) xlabel( Time(s) ) ylabel( y(t) ) title( Sin function ) legend( y=sin(t) ) y(t) 1.8.6.4.2 -.2 -.4 -.6 -.8 Sinusoidal function -1 2 4 6 8 1 12 14 Time(s) y=sin(t) Save the plot as.eps Use L A TEX command \includegraphics[width=2.5in]{sin1} Problems: Huge difference between font size of the text and figure Axes are not proportional Figure is not informative to the audience!
Figure size What is the size of your presentation? For a beamer slide: width=5.4 in, length=3.78 in What is the desired figure size? Figurewidth=4in, figureheight=2in Runfigure command before drawing the plot figure( Units, inches,... Position,[xy width height],... PaperPositionMode, auto ); (x,y)=position of the lower left side of the figure
Figure size 1.5 Sinusoidal function y=sin(t) y(t) -.5-1 5 1 15 Time(s) Dimensions are corrected Correction needed: Font size and type Axes limits Legend and labels to appear in L ATEX format
Axes settings Commands right after runningplot axis([ t(end) -1.5 1.5]) set(gca,... Units, normalized,... YTick,-1.5:.5:1.5,... XTick,:t(end)/4:t(end),... Position,[.15.2.75.7],... FontUnits, points,... FontWeight, normal,... FontSize,9,... FontName, Times ) Figure is exported to.eps
Axes setting Axes position, limits, font, and ticks locations are corrected y(t) Sinusoidal function 1.5 1 y=sin(t).5 -.5-1 -1.5 3.125 6.25 9.375 12.5 Time(s)
Labels and legend LATEX typesetting by settinginterpreter tolatex Labels can have different font sizes ylabel({ $y(t)$ },... FontUnits, points,... interpreter, latex,... FontSize,9,... FontName, Times ) xlabel( Time(s),... FontUnits, points,... FontWeight, normal,... FontSize,7,... FontName, Times )
Labels, legend, and L A TEX commands legend({ $y=\sin(t)$ },... FontUnits, points,... interpreter, latex,... FontSize,7,... FontName, Times,... Location, NorthEast ) title( Sinusoidalfunction,... FontUnits, points,... FontWeight, normal,... FontSize,7,... FontName, Times ) The figure is exported to.eps
Labels and legend Mathematical writing is corrected Figure has large white boundaries Fonts are not proportional to the values we want Sinusoidal function 2 y = sin(t) 1.5 y(t) 1.5 -.5-1 -1.5 3.125 6.25 9.375 12.5 Time(s)
How to save the plot Don t export the plot to.eps Useprint command to generate.eps files print -depsc2 myplot.eps Main vector formats -deps.eps black and white -depsc.eps color -deps2.eps level 2 black and white -depsc2.eps level 2 color -dpdf.pdf color file format
Exported.eps vs. printed.eps Exported.eps y(t) 2 1.5 1.5 -.5-1 Sinusoidal function y = sin(t) -1.5 3.125 6.25 9.375 12.5 Time(s) Printed.eps y(t) 2 1.5 1.5 -.5-1 Sinusoidal function y = sin(t) -1.5 3.125 6.25 9.375 12.5 Time(s)
Inserting.eps in L A TEX \includegraphics[options]{myplot} is useful to change the look of the.eps file Sinusoidal function 2 y(t) 1.5 1.5 -.5-1 -1.5 3.125 6.25 Time(s) 9.375
Ex. 1-1 -2-3 -4-5 2 4 6 8 1 6 4 2-2 (a) (Γ 11) 1 (b) (Γ 22) 1-1 -2-3 -4 2 4 6 8 1-5 -4 2 4 6 8 1 12 14 16 18 2 Time(s) (c) (Γ 12 ) 1 = (Γ 21 ) 1
Ex. 2 95 9 Step Down Newton Gradient Scalar 85 b D2(%) 8 75 7 Step Up 65 5 55 6 65 7 75 D 1 (%) a
Ex. 3 6 (a) (c) 6 Current(A) 4 2 4 2 C 1 252 C 3 4 5 5 C (b) 24 75 C 1 W/m 2 1 8 W/m 2 3 4 5 6 W/m 2 (d) 4 W/m 2 24 Power(W) 16 8 16 8 1 2 3 4 5 Voltage(V) 1 2 3 4 5 Voltage(V)
Ex. 4 PV module Power (W) 28 21 14 7 ( C, 1. kw/m 2 ) (25 C, 1. kw/m 2 ) (5 C, 1. kw/m 2 ) (25 C,.8 kw/m 2 ) (25 C,.6 kw/m 2 ) (25 C,.4 kw/m 2 ) Vw = 7 m/s Vw = 9 m/s Vw = 11m/s Vw = 13 m/s 2 15 1 5 Turbine power (kw) 1 2 3 4 5 Voltage(V) 2 4 6 8 1 12 Shaft speed (rad/s)
Ex. 5 6 15 Current(A) 4 2 1 5 Power(W) 1 2 3 4 5 Voltage(V) 1 2 3 4 5 Voltage(V)
Ex. 6 16 14 12 Pt (kw) 1 8 6 ES w/ inner control 4 ES w/o inner control P&O w/ FOC Pt 2 1 15 2 25 3 35 4 Time (s)
Ex. 7 7 35 35 65 38 4 6 35 38 44 42 43 3 4 445 D2(%) 55 43 38 35 5 42 4 45 3 35 38 4 4 45 5 55 6 65 7 D 1 (%)
Ex. 8 Turbine power, Pt (kw) 2 15 1 5 Vw = 7 m/s Vw = 9 Vw = 11 Vw = 13 P t = C p P w 2 4 6 8 1 12 Turbine speed, ω t (rad/s)
Export Simulink models (Not for publication) Change the orientation to portrait, landscape, or tall Open the model orient(gcs, portrait ) print the model to an.eps file specify the name of your Simulink model using the switch -s print -deps -r3 -s myfig.eps
Export Simulink models (Not for publication) Interpreted MATLAB Fcn yg(t) y_g y_g h_theta_g h_theta_g h_g_g s s+omega_h High pass 1 s K*u Fout Fin Interpreted MATLAB Fcn Sg(t) K_g Interpreted MATLAB Fcn Mg(t) Filter1 t y_n Interpreted MATLAB Fcn Interpreted MATLAB Fcn Sn(t) yn(t) Interpreted MATLAB Fcn Mn(t) h_g_n s s+omega_h y_n High pass1 1 s K*u Matrix Multiply Fout Fin -K_n Filter2 h_theta_n h_theta_n H h_h_n Interpreted MATLAB Fcn inv Gamma Riccati Sigma Fout Fin Filter3 Interpreted MATLAB Fcn N(t)
Diagrams in L A TEX Picture environment For mathematical drawings Very limited options Time consuming β = v/c = tanhχ χ u(k) x B (k) x C (k) y(k) H B (q) N[ ] H C (q)
Diagrams in L A TEX L A TEXCAD package Has a basic GUI Easy to use and very time saving Not precise, basic graphical elements with 3 different pen sizes Generates a L A TEX compatible.tex output S(t) θ ẋ = f(x,α(x,θ)) y = h(x) M(t) y s s+ω h ω l + K Λ z = y η s+ω s ΓĜ Ĝ l N(t) Ĥ ω l Σ Γ = ω r Γ ω r ΓĤΓ s+ω l
Diagrams in L A TEX L A TEXCAD package T 11,S 11 T 12,S 12 T 1n,S 1n I 1 PV 11 PV 12 PV 1n T 21,S 21 T 22,S 22 T 2n,S 2n PV 21 PV 22 PV 2n I 2 T m1,s m1 T m2,s m2 PV m1 + PV m2 V dc DC Bus T mn,s mn I m PV mn I dc
Diagrams in L A TEX L A TEXCAD package D Multivariable ES V dc I dc T 11,S 11 T 12,S 12 T 1n,S 1n I 1 PV 11 PV 12 PV 1n d 11 d 12 d 1n T 21,S 21 T 22,S 22 T 2n,S 2n I 2 PV 21 PV 22 PV 2n d 21 d 22 d 2n T m1,s m1 T m2,s m2 PV m1 + PV m2 T mn,s mn I m PV mn d m1 d m2 d mn V dc DC Bus I dc
Diagrams in L A TEX TikZ and PGF packages Many options and tools Very sophisticated Cover many types of diagrams Other useful extensions based on Tikz and PGF (T 1,S 1 ) I 1 Converter I o1 PV 1 V 1 V o1 Multivariable MPPT I (T 2,S 2 ) 2 PV 2 V 2 (Tn, Sn) In PVn Vn D 1 Converter I o2 D 2 Converter Dn Ion V o2 Von P = V dc I dc V dc I dc Inverter U inv I grid AC grid
Diagrams in L A TEX TikZ and PGF packages [(T 1,S 1 ),,(T n,s n )] T D S(t) D 1 DC/DC V 1 PV 1 P 1 D 2 DC/DC V 2 PV 2 P 2..... Dn DC/DC Vn PVn Pn P = V dc I dc M(t) High-pass filter + ˆD K s ΓĜ Ĝ Low-pass filter N(t) Γ = ργ ργĥγ Ĥ Low-pass filter
Diagrams in L A TEX TikZ and PGF packages SaA Output frequency = ωo SbA Input frequency = ωi Shaft and gearbox ScA Wind turbine B Matrix converter AC grid Wind speed = Vw Blade pitch angle = β Turbine speed = ωt Turbine inertia = Jt Ks Gearbox ratio = n Rotor inertia = J Generator IG Rotor frequency = ωr Pole pairs = p Rotor speed = ωr p vc vb va SaB SbB ScB SaC SbC ScC va vb vc N
Electrical circuits in L A TEX CrcuitTikZ package I1 IRF64 IL1 L1 LA 25-NP Io1 PV1 + C + V1 (T1, S1) I2 + PV2 V2 C 1 IR2127 IRF64 C 2 IL2 MUR22 L2 MUR22 IC1 rc1 LA 25-NP C2 IC2 Vo1 Io2 + Vo2 Electronic load + Vdc = 5V (T2, S2) IR2127 rc2 Idc PWM1 PWM2 ADC5 IL2 MPPT DS114 ADC6 ADC8 IC2 Vo2 ADC7 Vdc
How to convert L A TEX-produced figures into.eps Put figure in a separate L A TEX file Generate.dvi output using latex command Make sure figure fits in one page Convert.dvi to.eps using command line dvips -E figure.dvi-o figure.eps Open.eps file using ghostview and measure lower-left (Ax, Ay) and upper-right (Bx, By) coordinates Open.eps file using a text editor and look up %%BoundingBox: X1 Y1 X2 Y2 Replace X1 Y1 X2 Y2 with Ax Ay Bx By Command includegraphics with option clip prints only BoundingBox area on the output
References Damiano Varagnolo, How To Make Pretty Figures With Matlab, http://www.ee.kth.se/ damiano/matlab/howtomakeprettyfigureswithmatlab.pdf Version 8, 21. Yair Moshe, Advanced Matlab Graphics and GUI, http://sipl.technion.ac.il/new/download/matlab_support/matlab_guides/graphics%2and%2gui %2using%2Matlab.pdf November, 21. Richard E. Turner, Umesh Rajashekar Publication quality figures using Matlab, http://www.gatsby.ucl.ac.uk/ turner/teatalks/matlabfigs/matlabfig.pdf June, 211. Jeffrey D. Hein, Creating.eps figures using TikZ, http://heinjd.wordpress.com/21/4/28/creating-eps-figures-using-tikz/ April, 21.