MATLAB Answers

Tim Berk
1

Figures with large amounts of data don't export properly to .eps

Asked by Tim Berk
on 19 Sep 2017
Latest activity Answered by Luca Martinelli on 18 May 2018 at 14:03

I am plotting velocity fields using imagesc. These fields have a large amount of data (in this example 200*50 points which is already small) and I like to plot multiple axes in the same figure (in this example 6, so 200*50*6=60000 points). I save these as .eps files to load them into a latex document for an academic publication. When I export to .eps, either from the menu->save as, or using the print command the figure is not exported correctly (pixels are distorted, colors are mixed). See example (note that this is a small part of the figure but shows the issue):

One solution is to reduce the number of data points (here I use every third data point in both directions, reducing the amount of points by a factor 9):

The colors are now proper and it is a true vector image, but way too coarse for me.

Another solution is saving as .png:

Which draws the colours quite accurately, but now the lines and labels are obviously not vectorized anymore. (Note that this example image is not that good, but the results in the real .png are proper.)

Comments:

- I am now using Matlab2017a, but had the problem before in 2015a.

- This does not seem to be related to the renderer. The problem exists with both opengl and painters.

- It is not an .eps viewer problem. I have tried multiple .eps viewers. I might add that I can see from the file size that at some point matlab stops exporting as vector.

- It is not just related to imagesc. I have the same problem (actually even worse) with three dimensional slice plots.

- The only solution I have found is to export the velocity map separately without lines/axes/labels/annotations as a .png, export the lines/axes etc. as .eps and combine the two later on in the latex file. But this seems very tedious to me, especially when drawing 3D plots consisting of multiple slices.

I hope someone can tell me:

A) Why does matlab do this?

B) Is there a way to control this (i.e. change the number of points for which matlab decides not to create a vector image)?

C) In absence of a solution, what is the best way to combine separately exported velocity fields and lines/axes/annotations?

Thanks, Tim

  2 Comments

Please provide some data and code, such that the problem can be reproduced. Note that it is clear to you, what you consider as "pixels are distorted, colors are mixed". But the readers here see the posted graphics only and cannot guess, what you are expecting instead. So I ask for a clarification: What is the problem exactly and how can it be reproduced? How does the wanted output look like?

The data is quite large. Let me know if you still want the data and code after this explanation:

The question is regarding the colors (plotted with imagesc) only, not the contour line in front.

In the original post the second image shows an output as I expect. There are orange and green squares visible. Each square represents a data point in my imagesc input. The colors accurately represent the value I have input into the imagesc. Note that my colormap is orange->white->green, orange and green are totally separate.

The problem is with the first image in the original post. For this one I have used three times as much data points in each direction (9 times as much squares). I am using the exact same colormap and caxis. The problem is most apparent in the orange region, where a green blob shows up roughle in the middle. In general the colors are mixed.

To clarify the problem more, I have made a screenshot of the matlab figure (open in matlab) next to the exported .eps:

I think the picture speaks for itself. The exported .eps clearly is not a vector file. Orange and green colors are mixed and the pixels are distorted.

This problem only occurs when I use too many data points. This makes me think that matlab decides at some point: I can't process such a large vector file, lets try something else.

I am hoping to change this behaviour, such that my .eps files (and subsequently the pdf as created in LaTex appears exactly as the figure in Matlab. I'm hoping this is a known issue and someone knows the solution.

Sign in to comment.

Products

2 Answers

Answer by Tim Berk
on 20 Sep 2017
 Accepted Answer

In case anyone is ever interested here is how I solved it (a workaround really):

  • Create the figure
  • Delete the imagesc from the figure by using
im1 = imagesc(...);
im1.Visible = 'off';
  • Set background to transparent using
set(gcf,'Color','none')
  • Export the result (all lines/contourlines/axes/colorbars) as .eps using export_fig, disabling the crop functionality by -nocrop.
  • Create the figure again, now delete all lines/contourlines/axes/colorbars using
c1 = contour(...);
c1.Visible = 'off';
cb = colorbar;
cb.Visible = 'off';
ax1 = axes(...);
ax1.Box = 'off';
ax1.XAxis.Color = 'none';
ax1.YAxis.Color = 'none';
... etc
  • Export the result (only the imagesc generated backgrounds) as .png using export_fig, again with -nocrop option.
  • Combine the two figures in LaTex using Tikz

  0 Comments

Sign in to comment.


Answer by Luca Martinelli on 18 May 2018 at 14:03

Same problem here. My workaround is to save the .fig files, than go to a different laptop with the 2015 version of matlab and produce the .epsc file (with the saveas command), that can be imported in Latex.

No success with Metafiles.

  0 Comments

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today