How do I add ActionPostCallback to GUI axes
6 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Adam
on 14 Mar 2018
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 Comments
Adam
on 16 Mar 2018
Edited: Adam
on 16 Mar 2018
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.
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!