How do I add ActionPostCallback to GUI axes

9 ビュー (過去 30 日間)
Heine Hørup Pedersen
Heine Hørup Pedersen 2018 年 3 月 14 日
編集済み: Adam 2018 年 3 月 16 日
Using Matlab 2016b, I have used GUIDE to create a gui containing axes. I want to be able to control the XTick and XTickLabels shown in the plot. Therefore I try to add a callback to the zoom and pan event. During the axes create function I try to add a ActionPostCallback for zoom and pan. This works for the zoom part but it fails in the pan(hObject) part, since hObject is not a figure handle as far as I understand. How can I add a callback to the pan event?
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
set(zoom(hObject),'ActionPostCallback',@(x,y) XTickLabelCallbackFcn(hObject));
set(pan(hObject),'ActionPostCallback',@(x,y) XTickLabelCallbackFcn(hObject));
Error using uigetmodemanager (line 17) First argument must be a figure handle
Error in getuimode (line 12) hManager = uigetmodemanager(hFig);
Error in pan>locGetMode (line 290) hMode = getuimode(hFig,'Exploration.Pan');
Error in pan>locGetObj (line 220) hMode = locGetMode(hFig);
Error in pan (line 184) out = locGetObj(arg1);

回答 (1 件)

Adam
Adam 2018 年 3 月 14 日
Both zoom and pan should take a figure handle, which, by default, will be
handles.figure1
in a callback (or in the OpeningFcn which is where I usually put such things).
I always rename the tag from 'figure1' to something more sensible, but whatever your tag is for your figure is what would replace 'figure1'
  2 件のコメント
Heine Hørup Pedersen
Heine Hørup Pedersen 2018 年 3 月 16 日
Is it wrong to assume Axes handles are equivalent to Figure handles? The hObject is a [1x1 Axes]. I can apply a callback on the zoom event , but not the pan event.
Adam
Adam 2018 年 3 月 16 日
編集済み: Adam 2018 年 3 月 16 日
axes handles are not at all the same as figure handles. I am surprised you don't get an error with zoom if you are trying to use it with an axes handle.
A figure can contain any number of axes (or none at all) and the zoom function applies to the figure as a whole as the toolbar with the zoom icon is figure-level also. Though I notice in R2018a you can now add toolbars to axes, but they are not supported by having a zoom or pan object per axes so far as I can see.

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

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by