Get colorbar handle for a particular image
9 次查看(过去 30 天)
显示 更早的评论
If I have several images as subplots in a figure, how, given a handle to one of the images, or its axis, do I get the handle to the corresponding colorbar? Colorbars are not axes children, so how do I programmatically determine which belongs to which?
0 个评论
采纳的回答
Walter Roberson
2017-9-25
Assuming HG2:
get( ancestor(handle, 'axes'), 'Colorbar')
Or, if you already have the axes in variable ax then
ax.Colorbar
2 个评论
Walter Roberson
2017-9-25
I used my short routine to examine the axes properties; see https://www.mathworks.com/matlabcentral/answers/1325-what-is-missing-from-matlab#comment_472496
更多回答(1 个)
henk vang
2018-2-21
Somehow above answer did not work for me (R2014).
Suppose anyone is still looking: I think what you are looking for (and at least I was looking for) is something like:
if ~isappdata(gca,'ColorbarPeerHandle')
cb = getappdata(gca,'ColorbarPeerHandle');
end
I found a similar pices of code in the subfunction find_legend in the normal function legend. So find that piece of code, and replace ''LegendPeerHandle'' with ''ColorbarPeerHandle'.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!