1 | %PRINT2EPS Prints figures to eps with improved line styles
|
---|
2 | %
|
---|
3 | % Examples:
|
---|
4 | % print2eps filename
|
---|
5 | % print2eps(filename, fig_handle)
|
---|
6 | % print2eps(filename, fig_handle, options)
|
---|
7 | %
|
---|
8 | % This function saves a figure as an eps file, and improves the line style,
|
---|
9 | % making dashed lines more like those on screen and giving grid lines their
|
---|
10 | % own dotted style.
|
---|
11 | %
|
---|
12 | %IN:
|
---|
13 | % filename - string containing the name (optionally including full or
|
---|
14 | % relative path) of the file the figure is to be saved as. A
|
---|
15 | % ".eps" extension is added if not there already. If a path is
|
---|
16 | % not specified, the figure is saved in the current directory.
|
---|
17 | % fig_handle - The handle of the figure to be saved. Default: gcf.
|
---|
18 | % options - Additional parameter strings to be passed to print.
|
---|
19 |
|
---|
20 | % Copyright (C) Oliver Woodford 2008-2009
|
---|
21 |
|
---|
22 | % The idea of editing the EPS file to change line styles comes from Jiro
|
---|
23 | % Doke's FIXPSLINESTYLE (fex id: 17928)
|
---|
24 | % The idea of changing dash length with line width came from comments on
|
---|
25 | % fex id: 5743, but the implementation is mine :)
|
---|
26 |
|
---|
27 | function print2eps(name, fig, varargin)
|
---|
28 | options = {'-depsc2'};
|
---|
29 | if nargin < 2
|
---|
30 | fig = gcf;
|
---|
31 | elseif nargin > 2
|
---|
32 | options = [options varargin];
|
---|
33 | end
|
---|
34 | % Construct the filename
|
---|
35 | if numel(name) < 5 || ~strcmpi(name(end-3:end), '.eps')
|
---|
36 | name = [name '.eps']; % Add the missing extension
|
---|
37 | end
|
---|
38 | % Set paper size
|
---|
39 | old_mode = get(fig, 'PaperPositionMode');
|
---|
40 | set(fig, 'PaperPositionMode', 'auto');
|
---|
41 | % Print to eps file
|
---|
42 | print(fig, options{:}, name);
|
---|
43 | % Reset paper size
|
---|
44 | set(fig, 'PaperPositionMode', old_mode);
|
---|
45 | % Fix the line styles
|
---|
46 | try
|
---|
47 | fix_lines(name);
|
---|
48 | catch
|
---|
49 | warning('fix_lines failed. This is usually because the figure contains a large number of patch objects. Consider exporting to a bitmap format in this case.');
|
---|
50 | end
|
---|
51 | return
|
---|