1

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

Example: enter image description here enter image description here

Adam
  • 1,342
  • 7
  • 15
  • 1
    Are the pixels not "too small"? In that second figure, if you inspect the values of the data, are they still the same, or are they all zero? – Ander Biguri Sep 01 '17 at 11:26
  • the only difference between the two pictures is the xlim of the axes and in both cases xlim(2)-xlim(1) = 5 – Adam Sep 01 '17 at 11:37
  • Have you tried manually (re)setting `clim`? – Vahe Tshitoyan Sep 01 '17 at 11:52
  • @VaheTshitoyan `clim` stays the same (562.04) at the end of `keydownHandler` call – Adam Sep 01 '17 at 12:03
  • 3
    I think you're basically running into the same problem mentioned [here](https://stackoverflow.com/q/25342693/52738). You're trying to take a large number of image pixels in the x direction and display them with a relatively small number of screen pixels, causing particularly bad interpolation by the renderer MATLAB uses. – gnovice Sep 01 '17 at 14:18

0 Answers0