How do I add ActionPostCallback to GUI axes
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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 个评论
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 Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!