.eps format converts black pixels into white pixels
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Jaswanth
on 30 Apr 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.
0 Comments
See Also
Categories
Find more on Blue 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!