File Exchange

image thumbnail

fix_lines

version 1.5 (3.11 KB) by

Improves the style of lines in MATLAB generated eps files

28 Downloads

Updated

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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.

Comments and Ratings (17)

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!

Xianmin

Anton

Anton (view profile)

Thank a lot!

Carl Fischer

Finally! Thanks.

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

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.

Oliver Woodford

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

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.

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

Adam Nieslony

Adam Nieslony (view profile)

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

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

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

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?

Seb

Seb (view profile)

Work as i need. Thanks a lot!

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.

Rob Campbell

Rob Campbell (view profile)

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

gmart

gmart (view profile)

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

Updates

1.5

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

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

1.3

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

1.2

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

MATLAB Release
MATLAB 7.5 (R2007b)
Acknowledgements

Inspired by: FIXPSLINESTYLE

Inspired: export_fig

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

» Watch video