Borrar filtros
Borrar filtros

How can I save the imagesc to .eps with kept transparency on the mask?

26 visualizaciones (últimos 30 días)
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
And that's what's saved as .eps using
print('test.eps','-depsc','-painters')

Respuesta aceptada

Sourav Karmakar
Sourav Karmakar el 15 de Feb. de 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!

Más respuestas (0)

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by