MATLAB: Change the colormap of a figure using another GUI

colormapmatlab guiplotting

Hi,
I created a figure with pcolor map, and then I created a gui called figure prperties that let change the properties of the pcolor map like grid on/or off, color, line width.
the problem is that when use
colormap summer
or any other colormap (coper, winter, hot…)
the figure doesn't change, and it sems that the code in the GUI is not linked to the figure that I already created.

Best Answer

If multiple figures exist, running colormap without specifying which figure you are referring to can lead to such issues. Explicitly pass the handle of figure or axes. For example in your first code, get the handle of the axes object
fig = figure;
ax = axes(); % get handle of axes object
carte=pcolor(map_longitude,map_latitude,precipitation_change)
hold on
h = colorbar;
h.Label.String = 'Change in Precipitation (in %)';
colormap
Now pass the handle 'ax' to explicitly specify which axes are you referring to
if colour==1
colormap(ax, 'summer');
elseif colour==2
colormap(ax, 'winter');
elseif colour==3
colormap(ax, 'spring');
end