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 options using one or more name-value arguments in addition to any of the input
argument combinations in previous syntaxes. For example, to add a push button whose image is
contained in btn = axtoolbarbtn(tb,style,Name=Value)myfile.svg to the axes toolbar, set
Icon to "myfile.svg".
Examples
Create a custom state button for the axes toolbar that toggles the visibility of the axes grid lines.
First, create a program file named mycustomstatebutton.m. Within
the program file:
Plot random data.
Create a toolbar for the axes with options to zoom and restore the view using the
axtoolbarfunction.Add an empty state button to the toolbar using the
axtoolbarbtnfunction. Return theToolbarStateButtonobject.Specify the icon, tooltip, and callback function for the state button by setting the
Icon,Tooltip, andValueChangedFcnproperties. This example uses the icon, which you must first save as an image file namedmygridicon.svgon your path.
Run the program file, and click the icon to toggle the visibility of the grid lines.
function mycustomstatebutton plot(rand(5)) ax = gca; tb = axtoolbar(ax,{"zoom","restoreview"}); btn = axtoolbarbtn(tb,"state"); btn.Icon = "mygridicon.svg"; btn.Tooltip = "Grid Lines"; btn.ValueChangedFcn = @customcallback; function customcallback(src,event) switch src.Value case "off" event.Axes.XGrid = "off"; event.Axes.YGrid = "off"; case "on" event.Axes.XGrid = "on"; event.Axes.YGrid = "on"; end end end

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 named mycustompushbutton.m. Within
the program file:
Plot a surface.
Create a toolbar for the axes with options to zoom, rotate, and restore the view using the
axtoolbarfunction.Add an empty push button to the toolbar using the
axtoolbarbtnfunction. Return theToolbarPushButtonobject.Specify the icon, tooltip, and callback function for the push button by setting the
Icon,Tooltip, andButtonPushedFcnproperties, respectively. This example uses the icon, which you must first save as an image file namedmy2dicon.svgon your path.
Run the program file, and 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,{"zoom","rotate","restoreview"}); btn = axtoolbarbtn(tb,"push"); btn.Icon = "my2dicon.svg"; btn.Tooltip = "Snap to 2-D view"; btn.ButtonPushedFcn = @customcallback; function customcallback(src,event) view(event.Axes,2) end end

Input Arguments
Toolbar, specified as an AxesToolbar object. Create the toolbar
using the axtoolbar
function.
Button style, specified as one of these values:
"push"— Push button. When clicked once, the button is pressed and then released."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.
Example: axtoolbarbtn(tb,Icon="myimage.svg",Tooltip="My Icon
Tooltip")
Note
The properties listed here are only a subset. Push buttons and state buttons support different sets of properties. For a full list of properties and descriptions for each type, see the associated properties pages.
Button icon, specified as one of the following values. The axes toolbar displays icons as grayscale images. MATLAB® scales down the image to fit, if necessary.
Filename — Specify the filename as a string scalar or character vector. The filename can be preceded by a path. The file must be in SVG (since R2026a), PNG, JPEG, or GIF format.
m-by-n-by-3 array — Specify an m-by-n-by-3 array of RGB triplets that represent pixels in an image.
m-by-n 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 and 63. A value of 0 is opaque and a value of 63 is transparent. A value of
NaNis also transparent.If the values are of type
double, then specify values between 1 and 64. A value of 1 is opaque and a value of 64 is transparent. A value ofNaNis also transparent.
Name of predefined icon — Specify one of the names in this table. The color of the predefined icons changes automatically based on the theme of the figure.
Icon Name Result "export""brush""datacursor""rotate""pan""zoom"(since R2026a)"restoreview""zoomin""zoomout""none"No icon
Example: "icon.svg"
Example: "C:\Documents\icon.png"
Example: "rotate"
Button tooltip, specified as a string array, character vector, or cell array of character vectors. Use this property to display a message when you hover the pointer over the button. To display multiple lines of text, specify a string array or a cell array of character vectors. Each element in the array displays a separate line of text.
Example: "My Tooltip"
Version History
Introduced in R2018bYou can use SVG images for button icons on the toolbar. Specify Icon as the name of an SVG file. SVG icons allow for a sharper appearance than
icons of other formats.
The predefined icons are now in SVG format. These icons change automatically based on the theme of the figure.
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)