Search code examples
matlabepsmatlab-hg2

Matlab Graphics: Jagged Lines in Output


I am facing the issue of poor quality graphics output in Matlab similar to this question but the solutions given there did not work for me. Using either Matlab 2014b or 2015a results in the same issue.

Create an example figure with the following commands:

a = rand(200, 1)
b = .1 * rand(200, 1) + .4
plot([a b])
patch([1 100 100 1], [0 0 1 1], [-.1, -1., -.1, -.1], .1*ones(4, 1))
export_fig('test4.pdf')

The resulting image has jagged line joins and lines that overlap in an inconsistent way - sometimes the blue line is in front, sometimes orange line is.

enter image description here

Note that the problem is only present if the Z-data is included in the patch command.

I attempted to solve this problem the same way that was suggested in the question referenced above, but the provided procedure did not work (it made no changes to the .eps file). I manually edited the .eps file to have rounded line joins by changing the line

/J { setlinecap } def

to

/J { 1 setlinecap } def

However, the inconsistency of which line was in the foreground persisted.

enter image description here

Using the native output from Matlab results in the same issue as using export_fig. The line joins can be similarly fixed by editing the .eps file, this time replacing any lines of 2 setlinecap with 1 setlinecap, but which the line ordering issue remained.

I am then looking for the answer to one of two questions:

  • Is there a way to output a vector graphics image from Matlab that avoids both of these issues?
  • Is there a way to fix the line ordering issue by post-processing a file output by Matlab similarly to how the line-join issue can be fixed?

Solution

  • This issue is resolved in Matlab 2015b. There is no known work-around for 2014b or 2015a.