You are on page 1of 36

Preparing Figures in Matlab and LATEX for Quality

Publications

Azad Ghaffari

Cymer Center for Control Systems and Dynamics - UC San Diego

Second Edition, January 2014


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 = 0:.1:4*pi; 1

0.8
Sinusoidal function

y=sin(t)

y = sin(t); 0.6

0.4

plot(t,y) 0.2

xlabel(’Time(s)’)

y(t)
0

-0.2

ylabel(’y(t)’) -0.4

-0.6

title(’Sin function’) -0.8

legend(’y=sin(t)’) -1
0 2 4 6
Time(s)
8 10 12 14

◮ Save the plot as .eps


◮ Use LATEX 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.04 in, length=3.78 in

What is the desired figure size?

Figure width=4in, figure height=2in

Run figure command before drawing the plot

figure(’Units’,’inches’,...
’Position’,[x0 y0 width height],...
’PaperPositionMode’,’auto’);

(x0,y0) = position of the lower left side of the figure


Figure size
Sinusoidal function
1
y=sin(t)
0.5
y(t)

-0.5

-1
0 5 10 15
Time(s)

◮ Dimensions are corrected


◮ Correction needed:
◮ Font size and type
◮ Axes limits
◮ Legend and labels to appear in LATEX format
Axes settings

Commands right after running plot

axis([0 t(end) -1.5 1.5])


set(gca,...
’Units’,’normalized’,...
’YTick’,-1.5:.5:1.5,...
’XTick’,0: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

Sinusoidal function
1.5
y=sin(t)
1
0.5
y(t)

0
-0.5
-1
-1.5
0 3.125 6.25 9.375 12.5
Time(s)
Labels and legend
LATEX typesetting by setting interpreter to latex

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 LATEX commands

legend({’$y=\sin(t)$’},...
’FontUnits’,’points’,...
’interpreter’,’latex’,...
’FontSize’,7,...
’FontName’,’Times’,...
’Location’,’NorthEast’)
title(’Sinusoidal function’,...
’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
1
0.5
y(t)

0
-0.5
-1
-1.5
0 3.125 6.25 9.375 12.5
Time(s)
How to save the plot

Don’t export the plot to .eps

Use print 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
Sinusoidal function
2
y = sin(t)
1.5
1
0.5

y(t)
0
-0.5
-1
-1.5
0 3.125 6.25 9.375 12.5
Time(s)
Exported .eps
Sinusoidal function
2
y = sin(t)
1.5
1
0.5
y(t)

0
-0.5
-1
-1.5
0 3.125 6.25 9.375 12.5
Printed .eps Time(s)
Inserting .eps in LATEX
\includegraphics[options]{myplot} is useful to change the
look of the .eps file

tion
unc
al f
usoid
Sin

2
1.5
1 75
9.3
0.5
5
6.2
)

0
y(t

e(s)
Tim
-0.5 125
-1 3.

-1.5 0
Ex. 1

(a) (b)
0 0
-100 -100
-200 -200
-300 -300
-400 (Γ11 )−1 (Γ22 )−1 -400
-500 -500
0 20 40 60 80 100 0 20 40 60 80 100

(c)
60
40 (Γ12 )−1 = (Γ21 )−1
20
0
-20
-40
0 20 40 60 80 100 120 140 160 180 200
Time(s)
Ex. 2

95
Newton
Gradient
Scalar
90
Step Down

b
85
D2 (%)

80

75

70

Step Up
a
65
50 55 60 65 70 75
D1 (%)
Ex. 3

(a) (c)
6 6
Current(A)

4 4

2 2

0 0 ◦C 1000 W/m2 0
0 10 2520◦ C 30 40 50 0 10 800 W/m
20 2 30 40 50
50 ◦ C (b) 600 W/m2 (d)
240 240
75 ◦ C 400 W/m2
Power(W)

160 160

80 80

0 0
0 10 20 30 40 50 0 10 20 30 40 50
Voltage(V) Voltage(V)
Ex. 4

280 200
(00 ◦
C, 1.0 kW/m2 ) Vw = 7 m/s
(25 ◦
C, 1.0 kW/m2 ) Vw = 9 m/s
(50 ◦
C, 1.0 kW/m2 ) Vw = 11m/s
(25 ◦
C, 0.8 kW/m2 ) Vw = 13 m/s
(25 ◦
C, 0.6 kW/m2 )
210 150
(25 ◦
C, 0.4 kW/m2 )
PV module Power (W)

Turbine power (kW)


140 100

70 50

0 0
0 10 20 30 40 50 0 2 4 6 8 10 12
Voltage(V) Shaft speed (rad/s)
Ex. 5

6 150

4 100
Current(A)

Power(W)
2 50

0 0
0 10 20 30 40 50 0 10 20 30 40 50
Voltage(V) Voltage(V)
Ex. 6

160

140

120

100
Pt (kW)

80

60

ES w/ inner control
40 ES w/o inner control
P&O w/ FOC
Pt∗
20
10 15 20 25 30 35 40
Time (s)
Ex. 7
70
350 350

380
65 400

420
430
60 35
38
0
0 440
30

40

5
0

44
D2 (%)

55

430

380

350
42
0
50

400
35
38
45 0
0
30
0

40
40 45 50 55 60 65 70
D1 (%)
Ex. 8

200
Vw = 7 m/s
Vw = 9
Vw = 11
Vw = 13
Turbine power, Pt (kW)

150

100 Pt∗ = Cp∗ Pw

50

0
0 2 4 6 8 10 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 -r300 -s myfig.eps


Export Simulink models (Not for publication)
Interpreted
MATLAB Fcn
yg(t) y_g y_g

h_theta_g h_G_g s
High pass
s+omega_h
h_theta_g
1
K*u Fout Fin
s
K_g Filter1
Interpreted
Sg(t)
MATLAB Fcn
Interpreted
MATLAB Fcn
Mg(t)
t

y_n
Interpreted
MATLAB Fcn
yn(t) y_n
Interpreted
MATLAB Fcn
Mn(t) s
Interpreted High pass1
Sn(t)
MATLAB Fcn s+omega_h
h_G_n

1 Matrix
K*u Multiply Fin
s Fout
-K_n Filter2
h_theta_n
Interpreted
H Gamma Sigma Fout Fin
h_theta_n MATLAB Fcn
inv Filter3
h_H_n Riccati

Interpreted
MATLAB Fcn
N(t)
Diagrams in LATEX– Picture environment
◮ For mathematical drawings
◮ Very limited options
◮ Time consuming

β = v/c = tanh χ

✲ χ

u(k) xB (k) xC (k) y(k)


✲ HB (q) ✲ N [·] ✲ HC (q) ✲
Diagrams in LATEX– LATEXCAD package
◮ Has a basic GUI
◮ Easy to use and very time saving
◮ Not precise, basic graphical elements with 3 different pen sizes
◮ Generates a LATEX compatible .tex output

θ y
✲ ẋ = f (x, α(x, θ)) ✲
y = h(x) ❄
s
S(t) M (t) s+ωh

❄ Ĝ ωl ✛ ×❄
Λ z =y−η
+ ✛ K ✛ −ΓĜ ✛ s+ωl

s
✻ N (t)
Ĥ ωl Σ ❄
Γ̇ = ωr Γ − ωr ΓĤΓ✛ s+ωl
✛ ×✛
Diagrams in LATEX– LATEXCAD package

T11 , S11 T12 , S12 T1n , S1n ✛


I1
PV11 PV12 PV1n
T21 , S21 T22 , S22 T2n , S2n ✛
I2
PV21 PV22 PV2n

Tm1 , Sm1 Tm2 , Sm2 Tmn , Smn I✛


m
PVm1 PVm2 PVmn
Idc ✻
+ Vdc −
DC Bus
Diagrams in LATEX– LATEXCAD package

Vdc✛
D Multivariable ES Idc✛
T11 , S11 T12 , S12 T1n , S1n I1

PV11 PV12 PV1n
d11 ✻ d12 ✻ d1n ✻
T21 , S21 T22 , S22 T2n , S2n I2

PV21 PV22 PV2n
d21 ✻ d22 ✻ d2n ✻

Tm1 , Sm1 Tm2 , Sm2 Tmn , Smn I✛


m
PVm1 PVm2 PVmn
dm1 ✻ dm2 ✻ dmn ✻
I dc ✻
+ Vdc −
DC Bus
Diagrams in LATEX– TikZ and PGF packages
◮ Many options and tools
◮ Very sophisticated
◮ Cover many types of diagrams
◮ Other useful extensions based on Tikz and PGF
Converter
I1 Io1
(T1 , S1 )

PV1 V1 Vo1

P = Vdc Idc
D1

Converter Inverter
Multivariable MPPT

I2 Io2 Igrid
(T2 , S2 )

PV2 V2 Vo2 Vdc ∼


∼ AC grid
D2 Uinv

Converter
In Ion Idc
(Tn , Sn )

PVn Vn Von

Dn
Diagrams in LATEX– TikZ and PGF packages

[(T1 , S1 ), · · · , (Tn , Sn )]T

D1 DC/DC V1 PV1 P1
D D2 DC/DC V2 PV2 P2 P = Vdc Idc
. . . . .
. . . . .
. . . . .
Dn DC/DC Vn PV n Pn
High-pass
S(t) M (t)
filter
D̂ K Ĝ Low-pass
+ −ΓĜ ×
s filter
N (t)

Ĥ Low-pass
Γ̇ = ρΓ − ρΓĤΓ ×
filter
Diagrams in LATEX– TikZ and PGF packages

SaA

Output frequency = ωo SbA Input frequency = ωi

Shaft and gearbox ScA


Wind turbine
B Matrix converter AC grid
vA
Generator va SaB

vB
vb SbB
IG ∼ N
Ks vC
vc ScB
Turbine inertia = Jt

Gearbox ratio = n ∼
Rotor inertia = J

Rotor frequency = ωr

Rotor speed = ωpr


Pole pairs = p
Wind speed = Vw SaC
Blade pitch angle = β
Turbine speed = ωt SbC

ScC
Electrical circuits in LATEX– CrcuitTikZ package

I1 IRF640 IL1 L1 LA 25-NP Io1


PV1 + +
C
IC1
V1 C1′ MUR2020 Vo1

+
(T1 , S1 ) − IR2127 rC1

Electronic load

Vdc = 5V
I2 IRF640 IL2 L2 LA 25-NP Io2

PV2 + C2 +
IC2
C2′


V2 MUR2020 Vo2

(T2 , S2 ) − IR2127 rC2



Idc

IL2
PWM1 PWM2 ADC5
IC2
ADC6
DS1104 Vo2
MPPT ADC8
Vdc
ADC7
How to convert LATEX-produced figures into .eps

◮ Put figure in a separate LATEX 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, 2010.
Yair Moshe,
Advanced Matlab Graphics and GUI,
http://sipl.technion.ac.il/new/Download/Matlab_Support/Matlab_Guides/Graphics%20and%20GUI
%20using%20Matlab.pdf
November, 2010.
Richard E. Turner, Umesh Rajashekar
Publication quality figures using Matlab,
http://www.gatsby.ucl.ac.uk/˜turner/TeaTalks/matlabFigs/matlabFig.pdf
June, 2011.
Jeffrey D. Hein,
Creating .eps figures using TikZ,
http://heinjd.wordpress.com/2010/04/28/creating-eps-figures-using-tikz/
April, 2010.

You might also like