Code covered by the BSD License  

Highlights from
fix_lines

5.0

5.0 | 7 ratings Rate this file 34 Downloads (last 30 days) File Size: 3.11 KB File ID: #23604
image thumbnail

fix_lines

by Oliver Woodford

 

08 Apr 2009 (Updated 18 Aug 2010)

Improves the style of lines in MATLAB generated eps files

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

This function improves the style of lines in eps files generated by MATLAB's print function, making them more similar to those seen on screen. Grid lines are also changed from a dashed style to a dotted style, for greater differentiation from dashed lines.

The screenshot demonstrates the improvements, with the figure (top right) being printed to eps (bottom left), which is then improved (bottom right) using FIX_LINES. Note how the effect becomes more marked on thicker lines.

The function additionally moves any embedded fonts after the bounding box information, to ensure correct cropping in Ghostscript.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
FIXPSLINESTYLE
This submission has inspired the following:
export_fig

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
06 May 2009 gmart

i fixed the dashed line in my eps figure after running this function...

17 Jan 2010 Rob Campbell

Clear, well-written code that does the job. Very useful.

03 Jun 2010 Laurence K

Hi, I like this code - it has come in handy!

I was thinking that since the code has some error checking at the top, it should probably also take account of the situation where the file can't be opened. If that's the case at the moment (say the file isn't there) the line:

fh = fopen(fname, 'rt');

returns -1 into fh. That could be checked and acted on below that, for example like this:

[fh, fMsg] = fopen(fname, 'rt');
if ( fh == -1 )
  disp(['Error opening file: ' fMsg]);
  return;
end

Otherwise, an error is thrown when the fread line is executed, and it goes to close the file on the fclose line just below it. Since it's not open, this throws another error and the code exits with an error before the rethrow line is executed.

26 Jul 2010 Seb

Work as i need. Thanks a lot!

17 Aug 2010 D Ko

I tried using the script to improve my matlab-generated eps files (created using print('-depsc2','-tiff','-r600','filename.eps'])), but the output file cannot be read by ghostview.
I get the following message "DOS EPS header is bad". Ignoring DSC comments" in GV.
The Adobe Distiller-generated PDF for the eps file is a blank page.
Any idea?

17 Aug 2010 D Ko

Ok, I think I am getting somewhere now. When I remove the tiff preview option, it works just fine. So it seems like it works if the original doesn't have a -tiff attached to it. (I like the preview for when i import the graphic in a WYSIWYG word processor).

01 Apr 2011 Robert

Excellent! This makes figures look like they do on screen. For those of us who like GUIs, note that this also works if you save figures by clicking File>Save As... and select EPS (which opens in PDF viewers and word processors).

25 Aug 2011 Adam Nieslony

You are the best! The tool is simple and do exactly what I have expected. Thank you.

27 Nov 2011 Sauro Salomoni

Great script, does exactly what it's supposed to do. No more annoying thin slashes where there was supposed to be dots! Thanks

Please login to add a comment or rating.
Updates
14 Jan 2010

Better error recovery. Improved backwards compatibility. Reduced memory requirements.

13 Apr 2010

Move embedded fonts after bounding box info (for R2006b and earlier).

18 Aug 2010

Attempt to fix problem caused by tiff preview, as reported by D Ko (thanks). No error in ghostview now, though last drawn line disappears (only with tiff preview).

18 Aug 2010

Fix bug (only affecting R2006b & earlier) introduced in last update

Tag Activity for this File
Tag Applied By Date/Time
eps Oliver Woodford 09 Apr 2009 09:31:47
lines Oliver Woodford 09 Apr 2009 09:31:47
style Oliver Woodford 09 Apr 2009 09:31:47
width Oliver Woodford 09 Apr 2009 09:31:47
dash Oliver Woodford 09 Apr 2009 09:31:47
line style Oliver Woodford 09 Apr 2009 09:31:47
data export Oliver Woodford 09 Apr 2009 09:31:47
fix Oliver Woodford 09 Apr 2009 09:31:47
dashed line gmart 06 May 2009 22:04:42
potw Shari Freedman 14 Jan 2010 10:36:25
pick of the week Jiro Doke 11 Feb 2011 20:06:10
dashed line Raouf 16 May 2011 15:23:32
eps Florian Judex 09 Dec 2011 11:30:53

Contact us at files@mathworks.com