axtoolbarbtn
Add buttons to axes toolbar
Description
adds a push button to the axes toolbar specified by btn
= axtoolbarbtn(tb
)tb
and returns the
ToolbarPushButton
object.
specifies button properties using one or more name-value pair arguments.btn
= axtoolbarbtn(tb
,style
,Name,Value
)
Examples
Add State Button to Toolbar
Add a custom state button for the axes toolbar that turns on and off the axes grid lines.
First, create a program file called mycustomstatebutton.m
. Within
the program file:
Plot random data.
Create a toolbar for the axes with options to zoom in, zoom out, and restore the view using the
axtoolbar
function.Add an empty state button to the toolbar using the
axtoolbarbtn
function. Return theToolbarStateButton
object.Specify the icon, tool tip, and callback function for the state button by setting the
Icon
,Tooltip
, andValueChangedFcn
properties. This example uses the icon, which you must first save as an image file calledmygridicon.png
on your path.
When you run the program file, click the icon to turn on and off the grid lines.
function mycustomstatebutton plot(rand(5)) ax = gca; tb = axtoolbar(ax,{'zoomin','zoomout','restoreview'}); btn = axtoolbarbtn(tb,'state'); btn.Icon = 'mygridicon.png'; btn.Tooltip = 'Grid Lines'; btn.ValueChangedFcn = @customcallback; function customcallback(src,event) switch src.Value case 'off' event.Axes.XGrid = 'off'; event.Axes.YGrid = 'off'; event.Axes.ZGrid = 'off'; case 'on' event.Axes.XGrid = 'on'; event.Axes.YGrid = 'on'; event.Axes.ZGrid = 'on'; end end end
Add Push Button to Toolbar
Create a custom push button for the axes toolbar that snaps the view of the axes to a 2-D view.
First, create a program file called mycustompushbutton.m
. Within
the program file:
Plot a surface.
Create a toolbar for the axes with options to zoom in, zoom out, rotate, and restore the view using the
axtoolbar
function.Add an empty push button to the toolbar using the
axtoolbarbtn
function. Return theToolbarPushButton
object.Specify the icon, tool tip, and callback function for the push button by setting the
Icon
,Tooltip
, andButtonPushedFcn
properties, respectively. This example uses the icon, which you must first save as an image file calledmy2dicon.png
on your path.
When you run the program file, click the icon to snap the view of the axes to a 2-D view.
function mycustompushbutton surf(peaks(25)) ax = gca; tb = axtoolbar(ax,{'zoomin','zoomout','rotate','restoreview'}); btn = axtoolbarbtn(tb,'push'); btn.Icon = 'my2dicon.png'; btn.Tooltip = 'Snap to 2-D view'; btn.ButtonPushedFcn = @customcallback; function customcallback(src,event) view(event.Axes,2) end end
Input Arguments
tb
— Toolbar
AxesToolbar
object
Toolbar, specified as an AxesToolbar
object. Create the toolbar
using the axtoolbar
function, such as tb =
axestoolbar
.
style
— Button style
'push'
| 'state'
Button style, specified as one of these options.
Style | Description |
---|---|
'push' | Push button. When clicked once, the button appears to press and release. |
'state' | State button with two states. When clicked once, the button remains in the pressed or released state until it is clicked again. |
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: axtoolbarbtn(tb,'push','Icon','myimage.png','Tooltip','My Icon
Tooltip')
Note
The properties listed here are only a subset. Push buttons and state buttons support a different set of properties. For a full list of properties and descriptions for each type, see the associated property page.
Icon
— Button icon
'none'
(default) | file name | m-by-n-by-3 array | m-by-n matrix | predefined icon
Button icon, specified as one of these values. The axes toolbar displays icons as grayscale images. MATLAB® scales down the image to fit, if necessary.
File name — Specify the file name as a character vector or a string scalar. The file name can be preceded by a path. The image file must be in JPEG, GIF, or PNG format.
Array — Specify an m-by-n-by-3 array of RGB triplets that represent pixels in an image.
Matrix — Specify an m-by-n matrix of numeric values that represent pixels in an image.
If the values are of an integer type, then specify values between
0
and63
. A value of0
is opaque and a value of63
is transparent.NaN
is also transparent.If the values are of type
double
, then specify values between1
and64
. A value of1
is opaque and a value of64
is transparent.NaN
is also transparent.
Predefined icon — Specify one of the names in this table.
Icon Name Result 'brush'
'datacursor'
'export'
'rotate'
'pan'
'zoomin'
'zoomout'
'restoreview'
'none'
No icon
Example: btn.Icon = 'icon.png'
Example: btn.Icon = 'C:\Documents\icon.png'
Example: btn.Icon = 'rotate'
Tooltip
— Button tool tip
''
(default) | character vector | cell array of character vectors | string array
Button tool tip, specified as a character vector, cell array of character vectors, or a string array. Use this property to display a message when you hover the pointer over the button. To display multiple lines of text, specify a cell array of character vectors or a string array. Each element in the array displays a separate line of text.
Example: btn.Tooltip = 'My Tooltip'
Version History
Introduced in R2018b
See Also
Functions
Properties
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)