Colour changes from figure to png upon export

18 views (last 30 days)
Hi everyone, I am generating a plot using the code below where the lines plotted in the loops are in white and with a width of 0.2, however upon exporting the figure as a png the lines are exported in black. Does anyone know why the colour in the figure is different to the figure in the png
figure(1)
scatter(Table(:,2),Table(:,1),5,Table(:,3))
colormap('gray')
set(gca,'DataAspectRatio',[1 1 1])
set(gca,'fontsize',18)
xtickangle(45)
xlim([0 1800])
ylim([317 715])
for i=1:17
hold on
line([1,1800],[i*100,i*100],'Color','white','LineWidth',0.2)
end
for i=0:36
hold on
line([i*100,i*100],[0 900],'Color','white','LineWidth',0.2)
end
print(gcf,'Grids2','-dpng','-r1000');
  1 Comment
DGM
DGM on 5 Jan 2022
I can't seem to replicate the issue. For me, in R2019b, it exports with white lines.
The image is large (about 6000x7000px), so some viewers may be causing issues with nearest-neighbor display interpolation, so some features tend to disappear at most zoom levels. Still, that shouldn't be adding black lines.

Sign in to comment.

Answers (1)

DGM
DGM on 5 Jan 2022
I'm going to go out on a limb and guess that you're setting the axes color to something other than white.
set(gca,'color','r') % something like this?
Otherwise, the white grid would be invisible. If that's the case, then this may help:
set(gcf, 'InvertHardcopy', 'off')
and then call print().

Categories

Find more on Visual Exploration in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!