.eps format converts black pixels into white pixels

1 visualización (últimos 30 días)
Vincenzo Anania
Vincenzo Anania el 23 de Ag. de 2021
Respondida: Jaswanth el 30 de Abr. de 2024
Hi everyone,
I would like to save an image generated with imagesc using the ".eps" format, however, the parts of the image that should appear as black are converted into white. This is the code I use: first I generate the image, then I make sure that all NaN values appear as black and finally I save the image as an ".eps" file.
% Generate the image
cmap = parula(256);
colormap(cmap);
imagesc(my_data,'AlphaData', ~isnan(my_data), [50 100]);
set(gca, 'ytick',[], 'xtick',[],'FontSize',14,'Color', [0, 0, 0],'FontName','Times New Roman');
cb = colorbar('southoutside');
% Save the image
saveas(gcf,'my_figure','epsc')
Would you kindly know how to avoid this colour conversion?
Thanks a lot for your help,
Vincenzo

Respuestas (1)

Jaswanth
Jaswanth el 30 de Abr. de 2024
Hi Vincenzo,
To address the issue of ‘NaN’ values not displaying as black in your ‘.eps’ file outputs, you need to modify the colormap to include black for ‘NaN’values and adjust your data accordingly.
Kindly go through the following approach implementing these modifications:
Extend the Colormap: Add black at the beginning of the parula colormap to represent ‘NaN’values. This ensures ‘NaN’ values have a distinct color.
nanColor = [0, 0, 0]; % Black for NaN
cmap = [nanColor; parula(256)]; % New colormap
colormap(cmap); % Apply it
Adjust Data for NaN Representation: Map ‘NaN’values in your data to the black color in the new colormap. This step ensures ‘NaNs’are visually represented as black.
my_data(isnan(my_data)) = min(my_data(:)) - 1; % NaNs to black
Visualize and Save: Proceed with visualizing your data using imagesc and save the figure as an .eps file. The modified colormap will now accurately display ‘NaN’values as black.
imagesc(my_data, 'AlphaData', ~isnan(my_data), [50 100]); % Visualize data
colormap(cmap); % Apply the modified colormap
% Your existing visualization and saving code here
I hope that the information provided above is helpful in accomplishing your task.

Categorías

Más información sobre Blue en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by