Apart from the fact there exist special functions to plot vector fields, I have encountered a strange Matlab behaviour: Plotting an image (with imagesc or imshow) and overlaying it with colored lines (with plot or line) leads at some point to an erasement of the background image.
%% some data...
% random image
Image = rand(200,400);
% 900 lines of random color
color1 = rand(1,900);
color2 = rand(2,900);
color3 = rand(3,900);
% some positions
x = 31:60;
y = 31:60;
[X,Y] = meshgrid(x,y);
%% plot process
% plot Image (with 'imshow' or 'imagesc')
imshow(Image);
hold on;
% plot the lines (with 'line' or 'plot')
for i = 1:900
line([X(i), X(i)+1],[Y(i),Y(i)+2],'color',[color1(i),color2(i),color3(i)]);
if i == 100 % nothings happens to background image after 100 vectors
pause();
elseif i == 200 % gradually starts to change...
pause();
end
end
% ... at the end it is completely erased
Result: 100 lines

Result: 200 lines

Result: 900 lines

Nice side fact Saving the image as PNG restores the image (but destroys the line resolution).
This is not properly an answer, as it doesn't exactly explain why this is happening, but it provides a workaround, along with some more observations of the weird behaviour.
Scope:
I tried your example and indeed:
Workaround:
After a few trial and error, I worked out that it is a specific behaviour of the
painterrenderer in pre HG2 versions.If you change the renderer to any other than the default
painter, you get back your image and your superimposed lines.Observations:
Note that I also tried to:
uistack) => same black image.And to show you how persistent is the glitch:
claor evenclfthen re display the image => black frameThe only way I found to get the image displayed is to change the renderer as described above.
Printing/Saving
Initially, I thought the change of renderer was happening behind the scene when you were saving the figure, thereby allowing the final output to be fully displayed. Unfortunately, by exploring a bit more it doesn't seem to be so simple.
I tried different version with
print(instead ofsaveas) since it allows you to select the renderer. For each renderer I chose 2 formats,PDFwhich uses theghostscriptengine, andPNGwhich uses the Matlab engine:Well, after results I am still unsure of what is happening. All these saved figures show the proper image and the lines on top... But:
The 3x
pngimages (Matlabengine) are exactly similar. They do not even show slight difference in saturation like you can observe when you switch the renderer manually. This made me think that Matlab chose to ignore my renderer specification. It just decided which one was the most relevant and went ahead printing 3 times the same figure. So I thought may be thepainterrenderer wasn't used and that's why the images were shown.Well not so fast. On the 3x
pdfimages (ghostscriptengine) ... I can observe the small nuances between the 3 pictures ... so the renderer wasn't the same between them. Thepainterwas used on one of them, and successfully rendered the image.So in conclusion, it seems the
painterrenderer is only glitchy when applied to a (pre-HG2) figure!