Sem01!26!01 Jordan Rosenthal
Transcript of Sem01!26!01 Jordan Rosenthal
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
1/21
The Center for Signal & Image Processing Georgia Institute of Technology
26-Jan-2001
Creating and Exporting
Matlab Figures
Jordan Rosenthal
What you might not know, but should!
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
2/21
The Center for Signal & Image Processing2
26-Jan-2001jr
Purpose
Introduce you to
commands
techniques
you may not have seen before.
Somewhat random in nature
Convince you it's easy to do (let's hope!)
Not so much a tutorial as it is a survey
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
3/21
The Center for Signal & Image Processing3
26-Jan-2001jr
Creating Matlab Figures
Editing axes and text objects
Can change many properties without code
Run the following code
Change the line style and width
Change the axis title, x label, y label Change fonts
Add a grid
Annotate
Etc.
Matlab 5.3 (R11) Interactive features:
ezplot('cos(x)');
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
4/21
The Center for Signal & Image Processing4
26-Jan-2001jr
Creating Matlab Figures
Useful functions available for download:
sTitle = {'a','b','c','d'}
for i = 1:4
subplot(2,2,i);
imagesc(rand(16));
title( sTitle{i} );
end
pause;
suptitle('Main title');
suptitle.m : puts a title above all subplots
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
5/21
The Center for Signal & Image Processing5
26-Jan-2001jr
Creating Matlab Figures
Useful functions available for download:
arrow demo;
arrow.m : add an arrow to a plot
clf;
axis([-5 5 -5 5]);arrow([-4 -3],[2 3]);
arrow demo2;
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
6/21
The Center for Signal & Image Processing6
26-Jan-2001jr
Creating Matlab Figures
Adding LaTeX-like symbols to a plot:
clf;
h = remez(30,[0 0.4 0.6 1],[1 1 0 0]);
[H,w] = freqz(h);
plot( w/pi, abs(H) );
title('| H(e^{j\omega}) |');
xlabel('\omega / \pi');
Only a subset of LaTeX supported, but still useful
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
7/21
The Center for Signal & Image Processing7
26-Jan-2001jr
Creating Matlab Figures
Using FILL to create polygons:
clf;
ang = 2*pi/6 * ( 0 : 5 );
r = ones(1,6);
[x,y] = pol2cart(ang,r);
fill(x,y,'r','EdgeColor','k','LineWidth',3);
axis([-2 2 -2 2]);axis equal;
view(3);
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
8/21
The Center for Signal & Image Processing8
26-Jan-2001jr
Creating Matlab Figures
EASY to use lighting and visualization commands:
figure('Pos',[550 350 560 420]) ;
surf(peaks); axis tight; pause;
camlight headlight; pause;
shading interp; pause;
lighting phong; pause;
material metal; pause;
material shiny; pause;colorbar; pause;
colormenu;
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
9/21
The Center for Signal & Image Processing9
26-Jan-2001jr
Creating Matlab Figures
How to save on ink: (this plot still needs a little work)
cla; colormap(jet);
h = fspecial('average',7);
[H,w1,w2] =freqz2(h);
surfl(w1,w2,abs(H),'light');
shading interp; lighting phong;
colorbar;
colormap(gray); pause;
colormap(1-gray);
colormap( 1-rgb2gray(jet) ); pause;
brighten(0.5); pause;
material dull;
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
10/21
The Center for Signal & Image Processing10
26-Jan-2001jr
Export Problems
Property Export Problem
size plots too large and must be scaled down indocument
color want black and white, grayscale, or CMYKcolor
line widths typically too thin
font sizes typically wrong size
Problems when exporting to documents:
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
11/21
The Center for Signal & Image Processing11
26-Jan-2001jr
Export Example 1
x = 0 : 0.1 : 20;
y = sin(x);plot(x,y);
axis([0 20 -2 2]);
grid on;
cd z:\Staff\jr\MatlabPres;
print -deps2 example1.eps;
1)
2) Adjust aspect ratio
3)
4)Wrong aspect ratio
Show example1.eps
in GhostView
http://localhost/var/www/apps/conversion/releases/20121107221618/tmp/scratch_4/example1.epshttp://localhost/var/www/apps/conversion/releases/20121107221618/tmp/scratch_4/example1.epshttp://localhost/var/www/apps/conversion/releases/20121107221618/tmp/scratch_4/example1.eps -
7/30/2019 Sem01!26!01 Jordan Rosenthal
12/21
The Center for Signal & Image Processing12
26-Jan-2001jr
Export Example 1
A better way:
exportfig(gcf,'example1a.eps','width',6,...
'fontmode','fixed','fontsize',10);
Show example1a.eps
Usual Solution:
Scale plot in document
http://localhost/var/www/apps/conversion/releases/20121107221618/tmp/scratch_4/example1a.epshttp://localhost/var/www/apps/conversion/releases/20121107221618/tmp/scratch_4/example1a.eps -
7/30/2019 Sem01!26!01 Jordan Rosenthal
13/21
The Center for Signal & Image Processing13
26-Jan-2001jr
Export Example 2
x = 0 : 0.1 : 20;
y1 = sin(x); y2 = cos(x);plot(x,y1,x,y2);
legend('sin','cos');
axis([0 20 -2 2]);
grid on;title('Plot of sin and cos');
exportfig(gcf,'example2.eps', ...
'linestylemap','bw');
1)
2) Adjust aspect ratio (note colors)
3)
Show example2.eps4)
http://localhost/var/www/apps/conversion/releases/20121107221618/tmp/scratch_4/example2.epshttp://localhost/var/www/apps/conversion/releases/20121107221618/tmp/scratch_4/example2.eps -
7/30/2019 Sem01!26!01 Jordan Rosenthal
14/21
The Center for Signal & Image Processing14
26-Jan-2001jr
ExportFig Features
Can set session defaults
Can change height, width, or both
Can change color space
Can lock axes limits and ticks before export Fonts can scale with size or be fixed to a point size
Can use 'latin1' or 'adobe' character encoding
Line widths can be fixed or scaled and min/max
widths can be set Line style can be automatically mapped or mapped
according to user preferences
Can separate text into its own eps file
e.g., use bitmap image and overlay vectorized text
Everything you want from PRINT and more
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
15/21
The Center for Signal & Image Processing15
26-Jan-2001jr
Helper Files
PREVIEWFIG Preview a figure before exporting
APPLYTOFIG
Apply export options to a figure
RESTOREFIG
Restore figure to previous state
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
16/21
The Center for Signal & Image Processing16
26-Jan-2001jr
Importing into LaTeX
\usepackage{graphicx}
...\begin{figure}
\centering
\includegraphics{myfig.eps}
\caption{The figure caption}
\label{fig:CoolFigure}
\end{figure}
"Using Imported Graphics in LaTeX 2"
epslatex.ps, http://www.ctan.org
Everything
you need toknow
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
17/21
The Center for Signal & Image Processing17
26-Jan-2001jr
Importing into PowerPoint
PowerPoint does not support EPS
Can only display EPS files with a raster preview,typically TIFF
large files, sometimes causing memory problems
Use PNG, JPEG instead
Sometimes Matlab's Export menu works fine for this
Use EXPORTFIG
Yes, usually this means one file for visual
presentation and one for written paper
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
18/21
The Center for Signal & Image Processing18
26-Jan-2001jr
PowerPoint "Dissolve" Example
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
19/21
The Center for Signal & Image Processing19
26-Jan-2001jr
PowerPoint "Dissolve" Example
opt = struct('format','png','width',5, ...
'fontmode','fixed','fontsize',10, ...
'color','rgb');
surf(peaks);
exportfig(gcf,'example3a.png',opt);
shading interp;
exportfig(gcf,'example3b.png',opt);
camlight headlight; lighting phong;
exportfig(gcf,'example3c.png',opt);
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
20/21
The Center for Signal & Image Processing20
26-Jan-2001jr
PowerPoint "Dissolve" Example
Creating the dissolve:
Insert --> Picture --> From File
(PNGs were 10-30 kB)
(EPS with TIFF were 340-2500 kB!)
Place on top of each other
Slide Show --> Custom Animaton
Animate pictures on mouse click
Set effect to "dissolve"
-
7/30/2019 Sem01!26!01 Jordan Rosenthal
21/21
The Center for Signal & Image Processing21
26-Jan-2001jr
References
Matlab command help
ezplot, fill, surf, camlight, lightangle, shading, lighting,material, colorbar, colormap, brighten
User contributed files
http://www.mathworks.com/support/ftp/graphicsv5.shtml
suptitle.m, arrow.m
Matlab Digest Articles
Part I(http://www.mathworks.com/company/digest/june00/export/)
Part II(http://www.mathworks.com/company/digest/december00/export.shtml)
exportfig.m (updated), previewfig.m, applytofig.m, restorefig.m