Uploaded by lorenzo.roveda

2

advertisement
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
Core Objects
Axes
Plot Objects Group Objects
Hidden Annotation Axes
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
Sinusoidal function
1
y=sin(t)
0.8
0.6
0.4
0.2
y(t)
t = 0:.1:4*pi;
y = sin(t);
plot(t,y)
xlabel(’Time(s)’)
ylabel(’y(t)’)
title(’Sin function’)
legend(’y=sin(t)’)
0
-0.2
-0.4
-0.6
-0.8
-1
0
2
4
6
8
10
Time(s)
◮
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!
12
14
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)
y(t)
0.5
0
-0.5
-1
0
5
10
Time(s)
◮
◮
Dimensions are corrected
Correction needed:
◮
◮
◮
Font size and type
Axes limits
Legend and labels to appear in LATEX format
15
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
y(t)
0.5
0
-0.5
-1
-1.5
0
3.125
6.25
Time(s)
9.375
12.5
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
y(t)
1
0.5
0
-0.5
-1
-1.5
0
3.125
6.25
Time(s)
9.375
12.5
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
y(t)
1
0.5
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
y(t)
1
0.5
0
-0.5
-1
-1.5
Printed .eps
0
3.125
6.25
Time(s)
9.375
12.5
Inserting .eps in LATEX
\includegraphics[options]{myplot} is useful to change the
look of the .eps file
tion
unc
al f
oid
us
Sin
2
1.5
75
)
y(t
1
9.3
0.5
5
6.2
0
-0.5
-1
-1.5 0
3.
125
e(s)
Tim
Ex. 1
(a)
(b)
0
0
-100
-100
-200
-200
-300
-300
(Γ11 )−1
-400
-500
0
20
40
60
80
(Γ22 )−1
100
0
20
40
60
80
-400
-500
100
(c)
60
(Γ12 )−1 = (Γ21 )−1
40
20
0
-20
-40
0
20
40
60
80
100
Time(s)
120
140
160
180
200
Ex. 2
95
Newton
Gradient
Scalar
90
Step Down
D2 (%)
85
b
80
75
70
Step Up
a
65
50
55
60
65
D1 (%)
70
75
Ex. 3
(a)
Current(A)
6
6
4
4
2
2
0
0
10
0 ◦C
2520◦ C
30
40
50 ◦ C
75 ◦ C
240
Power(W)
(c)
50
(b)
0
1000 W/m2
10 800 W/m
20 2
600 W/m2
400 W/m2
30
40
50
(d)
0
240
160
160
80
80
0
0
10
20
30
Voltage(V)
40
50
0
10
20
30
Voltage(V)
40
50
0
Ex. 4
280
200
PV module Power (W)
210
C,
C,
◦
C,
◦
C,
◦
C,
◦
C,
◦
◦
1.0
1.0
1.0
0.8
0.6
0.4
Vw
Vw
Vw
Vw
kW/m2 )
kW/m2 )
kW/m2 )
kW/m2 )
kW/m2 )
kW/m2 )
=
=
=
=
7 m/s
9 m/s
11m/s
13 m/s
150
140
100
70
50
0
0
10
20
30
Voltage(V)
40
50
0
2
4
6
8
Shaft speed (rad/s)
10
12
0
Turbine power (kW)
(00
(25
(50
(25
(25
(25
6
150
4
100
2
50
0
0
10
20
30
Voltage(V)
40
50
0
10
20
30
Voltage(V)
40
50
0
Power(W)
Current(A)
Ex. 5
Ex. 6
160
140
Pt (kW)
120
100
80
60
ES w/ inner control
ES w/o inner control
P&O w/ FOC
Pt∗
40
20
10
15
20
25
Time (s)
30
35
40
Ex. 7
70
350
350
380
65
400
420
430
38
0
0
0
380
350
55
430
42
0
50
400
D2 (%)
440
40
0
5
35
30
44
60
0
38
0
35
45
0
30
40
40
45
50
55
D1 (%)
60
65
70
Ex. 8
200
Turbine power, Pt (kW)
Vw
Vw
Vw
Vw
=
=
=
=
7 m/s
9
11
13
150
Pt∗ = Cp∗ Pw
100
50
0
0
2
4
6
8
Turbine speed, ωt (rad/s)
10
12
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
s
h_G_g
s+omega_h
h_theta_g
1
s
Interpreted
MATLAB Fcn
High pass
K*u
Fin
Fout
Filter1
K_g
Sg(t)
Interpreted
MATLAB Fcn
Mg(t)
t
y_n
Interpreted
MATLAB Fcn
yn(t)
Interpreted
MATLAB Fcn
y_n
Interpreted
MATLAB Fcn
s
Mn(t)
Sn(t)
s+omega_h
h_G_n
1
s
K*u
Matrix
Multiply
Filter2
h_theta_n
H
h_theta_n
h_H_n
Interpreted
MATLAB Fcn
N(t)
Fin
Fout
-K_n
Interpreted
MATLAB Fcn
inv
Gamma
Sigma
Riccati
Fout
Fin
Filter3
High pass1
Diagrams in LATEX– Picture environment
◮
For mathematical drawings
◮
Very limited options
◮
Time consuming
β = v/c = tanh χ
✻
✲ χ
t
u(k)
✲
HB (q)
xB (k)
✲
N [·]
xC (k)
✲
HC (q)
y(k)
✲
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
θ
✲ ẋ = f (x, α(x, θ))
y = h(x)
M (t)
S(t)
❄
Ĝ
+ ✛ K ✛ −ΓĜ ✛
s
✻
ωl
s+ωl
Ĥ
Γ̇ = ωr Γ − ωr ΓĤΓ✛
y
✲
❄
s
s+ωh
Λ z =y−η
✛ ×❄
✛
ωl
s+ωl
N (t)
Σ ❄
✛ ×✛
Diagrams in LATEX– LATEXCAD package
T11 , S11
PV11
T12 , S12
PV12
T1n , S1n ✛
I1
PV1n
T21 , S21
PV21
T22 , S22
PV22
T2n , S2n ✛
I2
PV2n
Tm1 , Sm1 Tm2 , Sm2
PVm1 PVm2
+
Vdc
DC Bus
Tmn , Smn I✛
m
PVmn
Idc ✻
−
Diagrams in LATEX– LATEXCAD package
D
Multivariable ES
T11 , S11
PV11
d11 ✻
T21 , S21
PV21
d21 ✻
T12 , S12
PV12
d12 ✻
T22 , S22
PV22
d22 ✻
Tm1 , Sm1 Tm2 , Sm2
PVm1 PVm2
dm1 ✻ dm2 ✻
+
Vdc
DC Bus
Vdc✛
Idc✛
T1n , S1n
PV1n
d1n ✻
T2n , S2n
PV2n
d2n ✻
I1
✛
I2
✛
Tmn , Smn I✛
m
PVmn
dmn ✻
I
dc
−
✻
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
(T1 , S1 )
PV1
Io1
V1
Vo1
P = Vdc Idc
◮
D1
Converter
Multivariable MPPT
◮
I2
(T2 , S2 )
PV2
Inverter
Igrid
Io2
V2
Vo2
Vdc
∼
∼
AC grid
Uinv
D2
Converter
(Tn , Sn )
In
Ion
PVn Vn
Von
Dn
Idc
Diagrams in LATEX– TikZ and PGF packages
[(T1 , S1 ), · · · , (Tn , Sn )]T
D
D1
D2
.
.
.
Dn
DC/DC
DC/DC
.
.
.
DC/DC
V1
V2
.
.
.
Vn
PV1
PV2
.
.
.
PV n
P1
P2
.
.
.
Pn
M (t)
S(t)
+
P = Vdc Idc
D̂ K
s
−ΓĜ
Ĝ
Γ̇ = ρΓ − ρΓĤΓ
Low-pass
filter
Ĥ
High-pass
filter
×
Low-pass
filter
N (t)
×
Diagrams in LATEX– TikZ and PGF packages
SaA
Output frequency = ωo
Shaft and gearbox
SbA
Input frequency = ωi
ScA
Wind turbine
AC grid
Matrix converter
B
Generator
va
vb
SaB
SbB
vA
vB
Rotor inertia = J
vc
Rotor frequency = ωr
Pole pairs = p
Rotor speed = ωpr
Ks
Gearbox ratio = n
Wind speed = Vw
Blade pitch angle = β
Turbine speed = ωt
Turbine inertia = Jt
IG
ScB
SaC
SbC
ScC
vC
∼
∼
∼
N
Electrical circuits in LATEX– CrcuitTikZ package
(T1 , S1 ) −
MUR2020
IRF640
IL2 L2 LA 25-NP
◦
+
V2
(T2 , S2 ) −
C2′
MUR2020
PWM2
ADC5
ADC6
DS1104
MPPT
C2
IC2
rC2
IR2127
PWM1
+
Vo1
rC1
IR2127
I2
C
IC1
ADC8
ADC7
IL2
IC2
Vo2
Vdc
−
Io2
+
Vo2
−
+
C1′
Io1
Vdc = 5V
+
V1
PV2
IL1 L1 LA 25-NP
◦
Electronic load
PV1
IRF640
–
I1
Idc
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.
Download