File Exchange

image thumbnail

FIXPSLINESTYLE

version 1.2.0.1 (2.17 KB) by jiro
Fixes line styles in postscript files created from MATLAB® (PRINT command)

13 Downloads

Updated 01 Sep 2016

View License

FIXPSLINESTYLE: Fix line styles in exported post script files

FIXPSLINESTYLE(FILENAME) fixes the line styles in the postscript file FILENAME. The file will be over-written. This takes a .PS or .EPS file and fixes the dotted and dashed line styles to be a little bit more esthetically pleasing. It fixes the four default line styles (line, dotted, dashed, dashdot).

FIXPSLINESTYLE(FILENAME, NEWFILENAME) creates a new file NEWFILENAME.

This is meant to be used with postscript files created by MATLAB (print, export).
Example:
x = 1:.1:10;
y1 = sin(x);
y2 = cos(x);
h = plot(x, y1, '--', x, y2, '-.');
set(h, 'LineWidth', 2);
grid on;
legend('line 1', 'line2');

print -depsc test.eps
fixPSlinestyle('test.eps','fixed_test.eps');

Comments and Ratings (14)

I want to echo that this function appears to no longer work properly in R2018a. After running, without error, the output .eps is very small (close to 0 bytes), and cannot be opened.

Does not work for me. After I convert I try to open the new file and it says "the post script file "my file.eps" could not be converted to pdf

Nihad Ali

great! works perfectly.

neo svr

I think this submission has become redundant 2014b onwards. Matlab has changed the way they used to write eps files. For older versions, it is still useful, I used it for many years.

Alex

i have issues with matlab 2015 as well

marie

i have been using this function for years and it worked GREAT both on Matlab for Windows and MAC. However with my new installation (Windows 8/ Matlab 2015a), the function corrupts the eps file (reduces file size to almost 0 and cannot be opened by Adobe or, when transferring to MAC, Preview). It does not print any warning or error message though.

This problem has also been reported there:
https://github.com/masumhabib/PlotPub/issues/11

Can anyone reproduce this behavior? (to help fin the cause, and hopefully fix it!) thanks.

Jeremy

I've been looking for a good fix that works nicely with the default plotting commands. Thanks so much! Is there any way to increase the separation between dashes just a little bit?

jiro

Thanks for the feedback, Oliver. I'm glad to hear this inspired you to improve your own function. BTW, your print_pdf function is nice. It seems like you figured out a ways to make the grid lines separate from dashed lines.

This is a great idea, and one that inspired me to improve my own pdf rendering function, print_pdf. I've managed to get dash lengths to vary with line widths too, and make grid lines dotted rather than dashed. Thanks for the inspiration, Jiro!

Jiro Doke

Eric,
Thanks for your comments. I looked at the PS file and found out a way to not alter the grid. But I haven't figured out how to automate it. You can define another line style, and find out where the grid lines are defined. The issue is that the grid lines are simply defined like any other lines, so it's not straightforward to identify them.

K Hamed,
I'm not sure if it's the "recommended" way (I'm not an expert on Postscript), but "1 cap" or "1 setlinecap" creates a rounded end.

K Hamed

A trick I learned a long time ago from a friend is to replace the line: "0 cap" in the postscript file with "1 cap". This makes the edges of the lines rounder, which gives thick lines a nicer look, and also make dots round. Is this recommended or are there any side effects?

Eric Magee

This is very nice - I have always wished there was more control over the details of the line styles - guess we just have to mess with the PS file. Would there be any way of not "fixing" the line style of the grid?

Updates

1.2.0.1

Updated license

1.2.0.0

Copyright update.

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux