With the code below I generate an image which can be spanned via the arrow keys (left/right). The problem is that sometimes if the figure is thin enough and the window (the visible are of the image) is at the right position the whole image turns blue. If it were due to the pixels being too small I would expect this "blueness" regardless of where the window position is. The test data can be found at https://www.dropbox.com/s/rath8x3vxdbs0g6/data.csv?dl=0 (I couldn't reproduce the problem with random data)
I am using Matlab R2017a on Ubuntu 14.04.
function plottest()
%PLOTTEST Summary of this function goes here
% Detailed explanation goes here
f = figure('Toolbar','none','Menubar','none');
ax = axes(f);
signal = struct(...
'data',csvread('./data.csv'),...
'range',[0,562.04],...
'xdata',[0 10],...
'ydata',[0.5 127.5],...
'xlim',[0 5],...
'ylim',[0 128]);
set(ax,'Units','normalized');
set(ax,'Position',[0.1 0.1 0.8 0.8]);
h = imagesc(ax,[]);
colorbar(ax);
caxis(ax,signal.range);
set(ax,'YLim',signal.ylim);
set(ax,'XLim',signal.xlim);
set(h,'XData',signal.xdata);
set(h,'YData',signal.ydata);
set(h,'CData',signal.data);
signal.windowSize = signal.xlim(2) - signal.xlim(1);
guidata(f,signal);
set(f,'WindowKeyPressFcn',@keydownHandler);
end
function keydownHandler(obj,eventdata,~)
signal = guidata(obj);
if strcmp(eventdata.Key,'rightarrow')
ax = findobj(obj,'Type','Axes');
max_x = min([signal.xlim(2) + signal.windowSize*0.05,signal.xdata(2)]);
fprintf('Setting limit to [%f,%f]\n',max_x-signal.windowSize,max_x);
set(ax,'XLim',[max_x-signal.windowSize,max_x]);
elseif strcmp(eventdata.Key,'leftarrow')
ax = findobj(obj,'Type','Axes');
min_x = max([signal.xlim(1) - signal.windowSize*0.05,0]);
fprintf('Setting limit to [%f,%f]\n',min_x,min_x+signal.windowSize);
set(ax,'XLim',[min_x,min_x+signal.windowSize]);
else
return;
end
signal.xlim = get(ax,'XLim');
guidata(obj,signal);
end