change the colormap of a figure using another GUI

조회 수: 21 (최근 30일)
mahmoud zemzami
mahmoud zemzami 2020년 5월 20일
댓글: mahmoud zemzami 2020년 5월 29일
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.
  댓글 수: 2
KostasK
KostasK 2020년 5월 20일
Can you show us part of your code where you have the colormap summer included?
mahmoud zemzami
mahmoud zemzami 2020년 5월 20일
I created a GUI that create a figure with pcolor. Then I created another GUI in which I can change the properties of the figure.
Figure
the code that that creat the figure:
figure
carte=pcolor(map_longitude,map_latitude,precipitation_change)
hold on
h = colorbar;
h.Label.String = 'Change in Precipitation (in %)';
colormap
The code in the GUI that costumize the pcolor figure is
%grid on/off this is for a popup menu and it work perfectly
grid=get(handles.Grid,'Value');
if gridcolor ==1
set(carte, 'EdgeColor', 'black');
elseif gridcolor ==2
set(carte, 'EdgeColor', 'none');
end
% change color of the figure. this code is for a menu and it
% doens't work (nothing change in the plot)
colour=get(handles.colours,'Value');
if colour==1
colormap summer
elseif colour==2
colormap winter
elseif colour==3
colormap spring
end

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 20일
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
  댓글 수: 1
mahmoud zemzami
mahmoud zemzami 2020년 5월 29일
It works perfectely. Than's what I was looking for. Thank you bro.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rik
Rik 2020년 5월 20일
편집: Rik 2020년 5월 20일
Whenever you are working with a GUI: use explicit handles. Many functions accept handles to the affected object as an input, colormap is no exception.
Make sure your GUI has access to the handle of the axes object you want to modify.
For other advice about GUI design (and reasons why you should not start with GUIDE, as I'm seeing at the edge of your screenshot), see this thread.
colours=get(handles.colours,'String');
if get(handles.colours,'Value')>1 %skip '------'
colour=colours{get(handles.colours,'Value')};
end
colormap(ax,colour)
  댓글 수: 4
mahmoud zemzami
mahmoud zemzami 2020년 5월 21일
Ahh now I understand. Thank you so much for your precious help.
Rik
Rik 2020년 5월 21일
You're welcome. If you feel either answer solved your question, please consider marking it as accepted answer. If you think the other was helpful as well you can expres that with the upvote button.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by