Вы находитесь на странице: 1из 36

Preparing Figures in Matlab and L

A
T
E
X for Quality
Publications
Azad Ghaari
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 dicult

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 identier, called a handle

Set of characteristics, called properties

Possible to modify every single property using the command-line

Objects organized into a hierarchy


Core Objects Plot Objects Group Objects Annotation Objects
UI Objects
Axes Hidden Annotation Axes
Figure
Root
Avoid common mistakes
Dont

Use graphical commands with their default setting

Export gures using the export menu function

Modify gure properties using the mouse

Use third party graphics editors where possible


Do

Use functions and scripts to generate plots: Reuseability

Specify gure properties: Modifability

Generate your gures 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 gure
gca Handle of the current axis in the current gure
get Query the values of an objects properties
set Set the values of an objects properties
delet Delete an object
copyobj Copy graphics object
Example
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 2 4 6 8 10 12 14
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Time(s)
y
(t)
Sinusoidal function


y=sin(t)

Save the plot as .eps

Use L
A
T
E
X command
\includegraphics[width=2.5in]{sin1}
Problems:

Huge dierence between font size of the text and gure

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 gure size?
Figure width=4in, gure 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 gure
Figure size
0 5 10 15
-1
-0.5
0
0.5
1
Time(s)
y
(
t
)
Sinusoidal function


y=sin(t)

Dimensions are corrected

Correction needed:

Font size and type

Axes limits

Legend and labels to appear in L


A
T
E
X 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
0 3.125 6.25 9.375 12.5
-1.5
-1
-0.5
0
0.5
1
1.5
Time(s)
y
(
t
)
Sinusoidal function


y=sin(t)
Labels and legend
L
A
T
E
X typesetting by setting interpreter to latex
Labels can have dierent 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
T
E
X 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 gure 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
0 3.125 6.25 9.375 12.5
-1.5
-1
-0.5
0
0.5
1
1.5
2
y
(
t
)
Time(s)
Sinusoidal function


y = sin(t)
How to save the plot
Dont export the plot to .eps
Use print command to generate .eps les
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 le format
Exported .eps vs. printed .eps
Exported .eps
0 3.125 6.25 9.375 12.5
-1.5
-1
-0.5
0
0.5
1
1.5
2
y
(
t
)
Time(s)
Sinusoidal function


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


y = sin(t)
Inserting .eps in L
A
T
E
X
\includegraphics[options]{myplot} is useful to change the
look of the .eps le
0
3
.
1
2
5
6
.
2
5
9
.
3
7
5
-
1
.
5
-
1
-
0
.
5
0
0
.
5
1
1
.
5
2
y
(
t
)
T
i
m
e
(
s
)
S
i
n
u
s
o
i
d
a
l

f
u
n
c
t
i
o
n


Ex. 1
0 20 40 60 80 100
-500
-400
-300
-200
-100
0
(a)


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


(
22
)
1
0 20 40 60 80 100 120 140 160 180 200
-40
-20
0
20
40
60
(c)
Time(s)


(
12
)
1
= (
21
)
1
Ex. 2
50 55 60 65 70 75
65
70
75
80
85
90
95
D
2
(
%
)
D
1
(%)
Step Down
Step Up
b
a


Newton
Gradient
Scalar
Ex. 3
0 10 20 30 40 50
0
2
4
6
(a)
C
u
r
r
e
n
t
(
A
)
0 10 20 30 40 50
0
80
160
240
(b)
Voltage(V)
P
o
w
e
r
(
W
)


0

C
25

C
50

C
75

C
0 10 20 30 40 50
0
2
4
6
(c)
0 10 20 30 40 50
0
80
160
240
(d)
Voltage(V)


1000 W/m
2
800 W/m
2
600 W/m
2
400 W/m
2
Ex. 4
0 10 20 30 40 50
0
70
140
210
280
Voltage(V)
P
V

m
o
d
u
l
e

P
o
w
e
r

(
W
)


(00

C, 1.0 kW/m
2
)
(25

C, 1.0 kW/m
2
)
(50

C, 1.0 kW/m
2
)
(25

C, 0.8 kW/m
2
)
(25

C, 0.6 kW/m
2
)
(25

C, 0.4 kW/m
2
)
0 2 4 6 8 10 12
0
50
100
150
200
T
u
r
b
i
n
e
p
o
w
e
r
(
k
W
)
Shaft speed (rad/s)


V
w
= 7 m/s
V
w
= 9 m/s
V
w
= 11m/s
V
w
= 13 m/s
Ex. 5
0 10 20 30 40 50
0
2
4
6
Voltage(V)
C
u
r
r
e
n
t
(
A
)
0 10 20 30 40 50
0
50
100
150
Voltage(V)
P
o
w
e
r
(
W
)
Ex. 6
10 15 20 25 30 35 40
20
40
60
80
100
120
140
160
Time (s)
P
t
(
k
W
)


ES w/ inner control
ES w/o inner control
P&O w/ FOC
P

t
Ex. 7
3
0
0
3
0
0
3
5
0
3
5
0
3
5
0
350
350
380
3
8
0
3
8
0
3
8
0
400
4
0
0
4
0
0
4
2
0
420
4
3
0
430
4
4
0
4
4
5
D
2
(
%
)
D
1
(%)
40 45 50 55 60 65 70
40
45
50
55
60
65
70
Ex. 8
0 2 4 6 8 10 12
0
50
100
150
200
T
u
r
b
i
n
e
p
o
w
e
r
,
P
t
(
k
W
)
Turbine speed,
t
(rad/s)


P

t
= C

p
P
w
V
w
= 7 m/s
V
w
= 9
V
w
= 11
V
w
= 13
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 le

specify the name of your Simulink model using the switch -s


print -deps -r300 -s myfig.eps
Export Simulink models (Not for publication)
yn(t)
Interpreted
MATLAB Fcn
yg(t)
Interpreted
MATLAB Fcn
y_n
y_g
inv
Interpreted
MATLAB Fcn h_theta_n
h_theta_g
h_G_n
h_G_g
t
h_H_n
y_n
h_theta_n
y_g
h_theta_g
Sn(t)
Interpreted
MATLAB Fcn
Sg(t)
Interpreted
MATLAB Fcn
Riccati
Sigma Gamma
Matrix
Multiply
N(t)
Interpreted
MATLAB Fcn
Mn(t)
Interpreted
MATLAB Fcn
Mg(t)
Interpreted
MATLAB Fcn
K_g
K*u
1
s
1
s
High pass1
s
s+omega_h
High pass
s
s+omega_h
H
Filter3
Fin Fout
Filter2
Fin Fout
Filter1
Fin Fout
-K_n
K*u
Diagrams in L
A
T
E
X Picture environment

For mathematical drawings

Very limited options

Time consuming

= v/c = tanh
t
H
B
(q) N[] H
C
(q)

u(k) y(k) x
B
(k) x
C
(k)
Diagrams in L
A
T
E
X L
A
T
E
XCAD package

Has a basic GUI

Easy to use and very time saving

Not precise, basic graphical elements with 3 dierent pen sizes

Generates a L
A
T
E
X compatible .tex output
s
s+
h

l
s+
l
+
K
s
x = f(x, (x, ))

l
s+
l

y
z = y

y = h(x)

G
S(t)

N(t)
M(t)

=
r

r

Diagrams in L
A
T
E
X L
A
T
E
XCAD package
PV
21
PV
12
PV
1n
PV
2n
PV
mn
+
PV
22
PV
m2

PV
11
I
1
I
m

T
11
, S
11
T
12
, S
12
T
1n
, S
1n
T
21
, S
21
T
22
, S
22
T
2n
, S
2n
T
m1
, S
m1
T
m2
, S
m2
T
mn
, S
mn
DC Bus

I
dc
I
2
V
dc
PV
m1
Diagrams in L
A
T
E
X L
A
T
E
XCAD package
PV
21
PV
12
PV
1n
PV
2n
PV
mn
+
PV
22
PV
m2

PV
11
I
1
I
m

T
11
, S
11
T
12
, S
12
T
1n
, S
1n
T
21
, S
21
T
22
, S
22
T
2n
, S
2n
T
m1
, S
m1
T
m2
, S
m2
T
mn
, S
mn
DC Bus

I
dc
I
2

V
dc
PV
m1
Multivariable ES D



V
dc
I
dc

d
11
d
12
d
1n
d
21
d
22
d
2n
d
m1
d
m2
d
mn
Diagrams in L
A
T
E
X TikZ and PGF packages

Many options and tools

Very sophisticated

Cover many types of diagrams

Other useful extensions based on Tikz and PGF


PV
1
(T
1
, S
1
)
I
1
V
1
Converter
D
1
V
o1
I
o1
PV
2
(T
2
, S
2
)
I
2
V
2
Converter
D
2
V
o2
I
o2
PV
n
(T
n
, S
n
)
I
n
V
n
Converter
D
n
V
on
I
on
Inverter
V
dc
U
inv

I
dc

I
grid
AC grid
P
=
V
d
c
I
d
c
M
u
l
t
i
v
a
r
i
a
b
l
e
M
P
P
T
Diagrams in L
A
T
E
X TikZ and PGF packages
+
D
1
DC/DC V
1
PV
1
P
1
D
2
DC/DC V
2
PV
2
P
2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
D
n
DC/DC V
n
PV
n
P
n
High-pass
lter

Low-pass
lter
M(t) S(t)
K
s
N(t)

Low-pass
lter

=

H

G
[(T
1
, S
1
), , (T
n
, S
n
)]
T
P = V
dc
I
dc

D

G
D
Diagrams in L
A
T
E
X TikZ and PGF packages
v
a
v
b
v
c
IG
S
aA
S
bA
S
cA
S
aB
S
bB
S
cB
S
aC
S
bC
S
cC

v
A

v
B

v
C
N
Wind turbine
Shaft and gearbox
Generator
Matrix converter AC grid
Wind speed = V
w
Blade pitch angle =
Turbine speed =
t
B
K
s
T
u
r
b
i
n
e
i
n
e
r
t
i
a
=
J
t
G
e
a
r
b
o
x
r
a
t
i
o
=
n
R
o
t
o
r
i
n
e
r
t
i
a
=
J
Input frequency =
i
Output frequency =
o
R
o
t
o
r
f
r
e
q
u
e
n
c
y
=

r
P
o
l
e
p
a
i
r
s
=
p
R
o
t
o
r
s
p
e
e
d
=

r
p
Electrical circuits in L
A
T
E
X CrcuitTikZ package
C

1
IRF640
IR2127
MUR2020
L
1
I
L1
C
I
C1
r
C1
I
1
I
o1
+

V
1
+

V
o1

LA 25-NP
PV
1
(T
1
, S
1
)
C

2
IRF640
IR2127
MUR2020
L
2
I
L2
C
2
I
C2
r
C2
I
2
I
o2
+

V
2
+

V
o2

LA 25-NP
PV
2
(T
2
, S
2
)
E
l
e
c
t
r
o
n
i
c
l
o
a
d

+
V
d
c
=
5
V
I
dc
V
dc
V
o2
I
C2
I
L2
ADC
7
ADC
8
ADC
6
ADC
5
PWM
2
PWM
1
DS1104
MPPT
How to convert L
A
T
E
X-produced gures into .eps

Put gure in a separate L


A
T
E
X le

Generate .dvi output using latex command

Make sure gure ts in one page

Convert .dvi to .eps using command line


dvips -E figure.dvi -o figure.eps

Open .eps le using ghostview and measure lower-left (Ax, Ay)


and upper-right (Bx, By) coordinates

Open .eps le 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 gures using Matlab,
http://www.gatsby.ucl.ac.uk/

turner/TeaTalks/matlabFigs/matlabFig.pdf
June, 2011.
Jerey D. Hein,
Creating .eps gures using TikZ,
http://heinjd.wordpress.com/2010/04/28/creating-eps-figures-using-tikz/
April, 2010.

Вам также может понравиться