How can I save the imagesc to .eps with kept transparency on the mask?
20 views (last 30 days)
Show older comments
ANNA MARIA SKLODOWSKA
on 10 Feb 2022
Answered: Sourav Karmakar
on 15 Feb 2022
I have a problem with saving an image to .eps format with keeping the transparency of it.
my code is looking like that:
figure;
a = 0.2;
im = imagesc(t_ax,f,incl1(:,1:h).'); hold on
alpha(im,a);
imagesc(t_ax,f,incl11(:,1:h).','AlphaData',~isnan(incl11(:,1:h)).'); hold on
set(gca,'YDir','normal')
ylim([fmin fmax]);xlim([tmin tmax]);
colorbar
xlabel('Time [s]');
ylabel('Frequency [Hz]')
print('test.eps','-depsc','-painters')
The problem is, that incl11 is a matrix that contains values above some treshold and below this threshold, it is set to NaN.
When plotting the figure, everything seems nice. In the backgroun, there is full matrix with some transparency and on the top, is the described mask, but when I save figure as .eps, the NaN values are not transparent but white.
How can I fix it to have exact same figure in .eps as in .fig ?
Thanks a lot!
That's the printscreen from Matlab - my desired plot:
![print screen from Matlab - my desired plot](https://www.mathworks.com/matlabcentral/answers/uploaded_files/890465/print%20screen%20from%20Matlab%20-%20my%20desired%20plot.png)
And that's what's saved as .eps using
print('test.eps','-depsc','-painters')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/890470/image.png)
0 Comments
Accepted Answer
Sourav Karmakar
on 15 Feb 2022
Hey Anna Maria ,
As per my understanding, you want to save the image to ‘.eps’ format while keeping the transparency of it. Postscript file does not support transparency. Therefore, using '-painters' to generate an EPS figure using 'print' does not work.
As a workaround, you can use '-opengl', instead of '-painters'. Opengl creates an image of the onscreen figure. So, it is going to generate the 'eps' figure which will be the same as the FIG file.
A second workaround, depending on the workflow, is to export with PDF. 'Painters' supports transparency with 'pdf'. For example,
print('-painters','-dpdf','myfigure.pdf')
It won't be identical to EPS, but to get a similarly sized output the user can try setting the figure's ‘PaperSize’ to be the same as the figure's ‘PaperPosition’ width and height.
You can also refer to the following documentation for more reference:
Hope this helps!
0 Comments
More Answers (0)
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!