change the colormap of a figure using another GUI
8 ビュー (過去 30 日間)
古いコメントを表示
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
2020 年 5 月 20 日
Can you show us part of your code where you have the colormap summer included?
採用された回答
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 件)
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 件のコメント
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 Center および File Exchange で Colormaps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!