Can I use ButtonDownFcn on a figure axes not associated with a gui?

Using 2014b, I have a script that creates a figure with three axes, and plots some lines and a legend on each.
When the user clicks or zooms on one of the axes, I want it to call a certain function. I am attempting to use ButtonDownFcn for this, but the function is not being called.
I set all axes children to have HitTest off, and verified this is the case.
The code I use when creating the figure is:
set(fig_handle.CurrentAxes,'ButtonDownFcn', @set_ticks)
What am I doing wrong?

 採用された回答

Walter Roberson
Walter Roberson 2015 年 9 月 11 日

0 投票

Zoom and Pan mode replace the ButtonDownFcn with their own. For a broad range of versions before R2014b a work-around was known involving turning off a setting that was preventing the callbacks from being changed back. With Handle Graphics 2 in R2014b the way that Zoom and Pan work changed, and I have not yet heard any method to achieve this purpose (there might be one, I just might not have encountered it.)

1 件のコメント

Art
Art 2015 年 9 月 11 日
Thanks! I did some searching and trial and error and found this:
hpan = pan(fig_handle);
hpan.ActionPostCallback = @set_ticks;
hzoom = zoom(fig_handle.CurrentAxes);
hzoom.ActionPostCallback = @set_ticks
This works perfectly (I have the function insert text for the XTickLabels at the current auto-generated tickmarks, and reset them to the current XTicks if the axes is zoomed or panned)

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

その他の回答 (1 件)

Art
Art 2015 年 9 月 11 日

0 投票

So apparently my code IS working, but doesn't work when I have the Zoom or Pan buttons enabled. Is there a way to make ButtonDownFcn work from botton presses that originate from Zoom or Pan?

カテゴリ

ヘルプ センター および File ExchangeData Exploration についてさらに検索

タグ

質問済み:

Art
2015 年 9 月 11 日

コメント済み:

Art
2015 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by