imagesc is missing several rows of pixels when image has 1780 rows of pixel

% Simple demo to reproduce the bug.
% Purpose: show 2000x300 image by imagesc with yticklabel,
% then do "Y-only" zoom for fast free-hand eye-check of data quality in flexible Y ranges.
% Problem: imagesc shows misalignment with yticklabel in large images (2000X300)
% when doing Y-only zoom to a very high level.
% this may indicate missing of rows of pixles?
N = 2000;
A = rand(N,300);
imagesc(A)
set(gca,'YTick', 1:N,'YTickLabel',cellfun(@num2str,num2cell(1:N),'uni',0));
zoom yon
% then scrool to see
Hi,I am using imagesc to present the matrix data and need to view the details by Y-only zoom. When the number of row is not high, e.g., 300, after Y-only zoom I could see a perfect match of row of pixels with a ytick labelled. However, when the row numer is much higher as 1700, after Y-only zoom in the y-tick is ok, but the row of pixels does not match, as shown in image, It seems that several rows of pixels are lost in total, thus ytick is more dense than pixel rows. Is there a way to solve this problem? Thanks.

6 Comments

I'm more inclined to suspect that this has something to do with how the yticks are being set up.
% a test image
N = 100;
A = rand(N,10);
imagesc(A) % show it
yticks(1:N); % one tick per ypixel
ylim([20 30]) % zoom in on a small region
% a test image
N = 10000;
A = rand(N,10);
imagesc(A) % show it
yticks(1:N); % one tick per ypixel
ylim([20 30]) % zoom in on a small region
Perhaps you can put together a small working example which demonstrates the issue so that others can test it.
% demo to reproduce the bug.
N = 2000;
A = rand(N,300);
imagesc(A) % show it
set(gca,'YTick', 1:N,'YTickLabel',cellfun(@num2str,num2cell(1:N),'uni',0));
zoom yon
The xlim and ylim indeed re-plot only a portion of the entire image since the rest part cannot be retrieved by zoom out button/scroll, thus it is equivalent to the relative small images (which zooms with no such problem).
% a test image
N = 10000;
A = rand(N,300);
imagesc(A) % show it
set(gca,'YTick',(1:N)); % one tick per ypixel
zoom yon
ylim([20 30]) % small enough, thus no such problem
xlim([0 300])
This canvas only shows a 10x300 image, a small one that does not comes with such problem.
With your first example, I zoomed in and got this:
I'm running R2019b, so maybe something has changed. It smells like it.
I often use the forum editor to test things in $currentversion, but it doesn't support interactive view controls.
It is OK now.
I do not know what happened. Initially the bug was found in R2016a. I run the test code in R2017b and the tick is Ok.
Then I run in R2016a and found tick is also OK now.
The same file opened days ago in R2016a:
The same file opened just now in R2016a:
That's weird. Maybe there were some stale changes to the figure from it having been used prior. Even though I always clear an existing figure with clf before starting to use it, I find that doesn't always reset all the properties.

Sign in to comment.

Answers (0)

Asked:

on 24 Feb 2023

Commented:

DGM
on 26 Feb 2023

Community Treasure Hunt

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

Start Hunting!