View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 13 ratings Rate this file 24 Downloads (last 30 days) File Size: 3.11 KB File ID: #23604 Version: 1.5
image thumbnail




08 Apr 2009 (Updated )

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

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.


Fixpslinestyle inspired this file.

This file inspired Export Fig.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
31 Jan 2014 Jeremy

Jeremy (view profile)

This is the third fix I've tried for eps figures with default matlab line styles, and it's definitely the best of the three. Thanks!

25 Nov 2013 Xianmin

15 May 2013 Anton

Anton (view profile)

Thank a lot!

15 Aug 2012 Carl Fischer

Finally! Thanks.

15 Mar 2012 Jered Wells

Although, I do think it would be good to put in a warning if tiff preview is activated in the file being processed. It seems that a flaw which removes plot lines would be something of which the user should be made aware (along with the quick solution)!

Comment only
15 Mar 2012 Jered Wells

After hours of searching, it would have helped if I scrolled down the page to realize that I simply needed to remove tiff preview. I have no idea why my previous "workaround" worked, but it did. Thanks for your help, works great.

15 Mar 2012 Oliver Woodford

Jered: See my update comment from 18 August 2010. Don't save with tiff preview.

Comment only
15 Mar 2012 Jered Wells

Strangely enough, when using this program to fix plots with single lines, my line is missing from the plot! When fixing plots with multiple lines, the last line is missing! Even more strangely, when I open the .eps file in a standard text editor like Notepad (Windows 7 system), if I make a small edit (such as add a single space), then re-save, the EPS file loads correctly into my Word document! Ever heard of this problem? I've search everywhere for solutions and cannot seem to find any. Will re-rate when solution is found.

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

25 Aug 2011 Adam Nieslony

Adam Nieslony (view profile)

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

01 Apr 2011 Robert

Robert (view profile)

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).

17 Aug 2010 D Ko

D Ko (view profile)

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).

Comment only
17 Aug 2010 D Ko

D Ko (view profile)

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?

Comment only
26 Jul 2010 Seb

Seb (view profile)

Work as i need. Thanks a lot!

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]);

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.

17 Jan 2010 Rob Campbell

Rob Campbell (view profile)

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

06 May 2009 gmart

gmart (view profile)

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

14 Jan 2010 1.2

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

13 Apr 2010 1.3

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

18 Aug 2010 1.4

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 1.5

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

Contact us