Axes in dialog box turn blank after calling imagesc in pushbutton callback
Mostrar comentarios más antiguos
Question: Why axes in dialog box go blank after calling imagesc from pushbutton callback? I call first imagesc after creation of axes and this works. But when axes are to be updated pushing the button, they go blank. I checked cData property of axes image object and it changed everytime after pushing the button.
MWE:
Dlg();
function Dlg()
% dialog window
d = dialog('Name', 'Random image', 'Position', [100 100 400 200]);
% axes
ax1 = axes('parent', d, 'Position', [0.45 0.1 0.5 0.8]);
imagesc(ax1, randi(10,10))
colormap(ax1, 'jet')
% pushbutton
uicontrol('Parent', d, 'Style', 'pushbutton', 'Position', [20, 130, 100, 50], ...
'String', 'Imagesc', 'Callback', @BtnPushed)
% pushbtn callback
function BtnPushed(~, ~)
imagesc(ax1, randi(10,10))
colormap(ax1, 'jet')
end
end
Thanks for explanation.
Respuesta aceptada
Más respuestas (1)
TL;DR This issues has been fixed in R2025a. Prior to R2025a, fix it by specifying the number of colors in jet()
function BtnPushed(~, ~)
imagesc(ax1, randi(10,10))
colormap(ax1, jet(256)) % <-----
end
What's happening
This stumped me for a bit. By default, figures produced by dialog have an empty colormap. When you specify a colormap using a string such as colormap(h,'jet'), it defines the number of colors in the colormap based on the figure's default colormap size. However, since dialog figures have an empty colormap, the colormap you're assigning is 0x3 which is no colormap at all. You can see that by calling,
colormap(ax1, 'jet')
size(ax1.Colormap)
> 0×3 empty double matrix
When you specify a colormap using an input argument, your colormap will have a non-zero height.
Another way this could have been fixed is by assigning a colormap to the dialog figure
d = dialog(__,'colormap',jet(256));
or by using a regular figure which has a non-empty default colormap and set to a modal WindowStyle to emulate dialog behavior.
d = figure('Name', 'Random image', 'Position', [100 100 400 200],'WindowStyle','modal')
1 comentario
Tomas Paliesek
el 30 de Mzo. de 2023
Categorías
Más información sobre White en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!