axtoolbar cannot create some buttons

3 次查看(过去 30 天)
Dear all,
As someone else already posted, the documented function axtoolbar seems to work in creating some of the user requested tool buttons (i.e. zoom in, zoom out, restore view, pan, etc), but it left out some other buttons (in particular the "datacursor" one).
After some investigations, I found out that the buttons are created by a second function (in R2021a it appear in the axtoolbar definition file at line 197), matlab.graphics.controls.ToolbarController.createToolbarButton (a p-file function placed in "\MATLAB\R2021a\toolbox\matlab\graphics\+matlab\+graphics\+controls\@ToolbarController\ToolbarController.p") which seems to accept two inputs: a cell containing a character vector with the name of the button to be created and the target axes. The available button names are 15, and the following code show the results of calling the said function with each of them. As you can see in the snippet at the end of this post, the "stepzoomout", "stepzoomin" and "datacursor" names do not produce any output, neither an error/warning message. I can imagine that the two step zoom buttons may interfer with the standard zoom ones, but why the "datacursor" is not working? Is that a bug from MathWorks or is intended? Is it due to some incompatibility maybe?
If someone ask, I already found (and implemented in another project) a workaround: the manual definition of all the required buttons (zoom, pan, datacursor,...) using the built-in icons but with custom callbacks that 1) enable/disable the other buttons and 2) activate the relative function using the associated commands (zoom, pan, datacursormode), but as you can imagine is very tedious.
Thanks in advance for any help,
Jacopo
Notes:
OS: Windows 10
OS Build: 19044
Matlab version: R2021a Update5
Tested axes: uiaxes in uifigure with multiple plots object in it
K>> for idx=1:15
idx
btnName=buttonTypesEnum(idx)
matlab.graphics.controls.ToolbarController.createToolbarButton(btnName, parentAxes)
end
idx =
1
btnName =
1×1 cell array
{'restoreview'}
ans =
ToolbarPushButton (Restore View) with properties:
Tooltip: 'Restore View'
Icon: 'restoreview'
ButtonPushedFcn: @(e,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true)
Show all properties
idx =
2
btnName =
1×1 cell array
{'zoomout'}
ans =
ToolbarStateButton (Zoom Out) with properties:
Tooltip: 'Zoom Out'
Icon: 'zoomout'
ValueChangedFcn: @(e,d)matlab.graphics.interaction.webmodes.toggleMode(d.Axes,'zoomout',d.Value)
Show all properties
idx =
3
btnName =
1×1 cell array
{'zoomin'}
ans =
ToolbarStateButton (Zoom In) with properties:
Tooltip: 'Zoom In'
Icon: 'zoomin'
ValueChangedFcn: @(e,d)matlab.graphics.interaction.webmodes.toggleMode(d.Axes,'zoom',d.Value)
Show all properties
idx =
4
btnName =
1×1 cell array
{'stepzoomout'}
ans =
[]
idx =
5
btnName =
1×1 cell array
{'stepzoomin'}
ans =
[]
idx =
6
btnName =
1×1 cell array
{'pan'}
ans =
ToolbarStateButton (Pan) with properties:
Tooltip: 'Pan'
Icon: 'pan'
ValueChangedFcn: @(e,d)matlab.graphics.interaction.webmodes.toggleMode(d.Axes,'pan',d.Value)
Show all properties
idx =
7
btnName =
1×1 cell array
{'rotate'}
ans =
ToolbarStateButton (Rotate 3D) with properties:
Tooltip: 'Rotate 3D'
Icon: 'rotate'
ValueChangedFcn: @(e,d)matlab.graphics.interaction.webmodes.toggleMode(d.Axes,'rotate',d.Value)
Show all properties
idx =
8
btnName =
1×1 cell array
{'datacursor'}
ans =
[]
idx =
9
btnName =
1×1 cell array
{'brush'}
ans =
ToolbarStateButton (Brush/Select Data) with properties:
Tooltip: 'Brush/Select Data'
Icon: 'brush'
ValueChangedFcn: @(e,d)matlab.graphics.interaction.webmodes.toggleMode(d.Axes,'brush',d.Value)
Show all properties
idx =
10
btnName =
1×1 cell array
{'export'}
ans =
ToolbarDropdown (export) with properties:
Tag: 'export'
Icon: 'export'
Children: [3×1 ToolbarPushButton]
Show all properties
idx =
11
btnName =
1×1 cell array
{'saveas'}
ans =
ToolbarPushButton (Save As) with properties:
Tooltip: 'Save As'
Icon: 'saveas'
ButtonPushedFcn: [function_handle]
Show all properties
idx =
12
btnName =
1×1 cell array
{'copyimage'}
ans =
ToolbarPushButton (Copy as Image) with properties:
Tooltip: 'Copy as Image'
Icon: 'copyimage'
ButtonPushedFcn: [function_handle]
Show all properties
idx =
13
btnName =
1×1 cell array
{'copyvector'}
ans =
ToolbarPushButton (Copy as Vector Graphic) with properties:
Tooltip: 'Copy as Vector Graphic'
Icon: 'copyvector'
ButtonPushedFcn: [function_handle]
Show all properties
idx =
14
btnName =
1×1 cell array
{'default'}
ans =
7×1 graphics array:
ToolbarPushButton (Restore View)
ToolbarStateButton (Zoom Out)
ToolbarStateButton (Zoom In)
ToolbarStateButton (Pan)
ToolbarStateButton (Rotate 3D)
ToolbarStateButton (Brush/Select Data)
ToolbarDropdown (export)
idx =
15
btnName =
1×1 cell array
{'none'}
ans =
[]
  1 个评论
Jacopo Remondina
Jacopo Remondina 2022-4-20
Update: further testing done in MATLAB 2021b show that the example provided in axtoolbar documentation works while working with figures (GUIDE environment), but not in uifigures (appdesigner).
The problem still remains....

请先登录,再进行评论。

回答(1 个)

R
R 2024-1-22
I could reproduce this issue in MATLAB R2021b. It seems like the 'datacursor' button is available from MATLAB R2023a onwards in the 'uifigure'. As a workaround, I used the following code (tested in MATLAB R2021b):
f = uifigure();
ax = uiaxes(f);
plot(ax,magic(5));
% collect the axtoolbar, and add custom button
tb = axtoolbar(ax,"default");
axtoolbarbtn(tb,"state","Icon","datacursor","Tooltip","Data Tips",...
"ValueChangedFcn",@(e,d)datacursormode(ancestor(d.Source,'figure'),d.Value));

类别

Help CenterFile Exchange 中查找有关 Interaction Control 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by