Get colorbar handle for a particular image

10 ビュー (過去 30 日間)
Matt J
Matt J 2017 年 9 月 25 日
回答済み: henk vang 2018 年 2 月 21 日
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?

採用された回答

Walter Roberson
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 件のコメント
Matt J
Matt J 2017 年 9 月 25 日
OK, that's easy. But what still puzzles me is that 'Colorbar' appears neither in the properties list nor methods list of axes objects. How did you know that it was there !?
Walter Roberson
Walter Roberson 2017 年 9 月 25 日

サインインしてコメントする。

その他の回答 (1 件)

henk vang
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'.

Community Treasure Hunt

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

Start Hunting!

Translated by