MATLAB Answers

How do I customize a figure toolbar by removing certain buttons?

125 views (last 30 days)
I would like to customize the MATLAB figure window by having the ability to remove certain buttons from the figure toolbar. For instance, I do not want my figure windows to have a "Save Figure" button.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
For releases prior to MATLAB 7.0 (R14) refer to the Related Solution listed at the bottom of the page.
For MATLAB 7.0 (R14) and all subsequent releases:
The following code will help illustrate how this can be achieved.
% If I want to disable the Save Figure button on the toolbar
a = findall(gcf)
b = findall(a,'ToolTipString','Save Figure')
FIGURE generates an empty figure window.
FINDALL gets a list of all graphics objects in the current figure window and assigns it to the variable “a”
Note that as you move your mouse across the various figure toolbar buttons, a yellow colored ToolTipString shows up indicating what each figure toolbar button does. This ToolTipString will be used to customize the figure toolbar by removing certain buttons. In the code above, we execute a second FINDALL command to find all objects assigned to the variable “a” that have the ToolTipString "Save Figure", and assign that to the variable “b”
SET sets all instances of Save Figure that are returned to “b” as OFF. These instances are no longer visible resulting in the "Save Figure" button no longer showing up in the figure toolbar.
It is extremely important that you spell the ToolTipString correctly and just as it appears when you move your mouse over a figure toolbar button. A list of ToolTipString (s) available in MATLAB 7.0.4 (R14SP2) are included below as a reference:
uipushtool buttons
(1) Show Plot Tools
(2) Hide Plot Tools
(3) Print Figure
(4) Save Figure
(5) Open File
(6) New Figure
uitoggletool buttons
(1) Insert Legend
(2) Insert Colorbar
(3) Data Cursor
(4) Rotate 3D
(5) Pan
(6) Zoom Out
(7) Zoom In
(8) Edit Plot
Nicolas Pipard
Nicolas Pipard on 29 Mar 2021
That definitly helped me. If my toolbar is not needed later, it's a very nice approach. Here is what I did with your suggestion to improve the speed of ginput:

Sign in to comment.

More Answers (1)

Scott Nuccio
Scott Nuccio on 26 Jun 2019
Edited: MathWorks Support Team on 24 Nov 2020
Baiscally, you can use the 'allchild' command to retrieve the toolbar handle. You can use it again on the toolbar to get all of the pushbuttons, etc. and then set their properties as you see fit.
hFigChildren=allchild(gcf); % retrieve all hidden children
hToolbarChildren=allchild(hFigChildren(end)); % retrieve all hidden children of the toolbar
hToolbarChildren(13).Visible='off'; % hide the 'Save Figure' pushtool
Now that you can see whats there, you can use the 'findall' function to streamline this if you know exactly what you want, and to prevent things from moving around since the example code is hard coded based on the order that the children are retrieved, and will change if things get added to the figure.
Also, if you want to add buttons. My script for adding buttons to the toolbar is called 'figToolbarFix.m' and lives in my 'user -> documents -> matlab' folder
function [] = figToolbarFix(hFig)
%UNTITLED2 Summary of this function goes here
% Customize the default figure toolbar
% hFig = handle of figure to be customized
% Example: figToolbarFix(gcf);
% Example: hFig=figure; figToolbarFix(hFig);
% enable the old 'zoom', 'rotation', 'pan', 'data tips', etc., buttons
% load a pretty images to use for our buttons. Check MATLAB\release\toolbox\matlab\icons for other options, or
% make your own. Note the double conversion (rgb -> ind -> rgb) to normalize a png image.
[img1,map1] = rgb2ind(imread(fullfile(matlabroot,...
[img2,map2] = imread(fullfile(matlabroot,...
% Convert image from indexed to truecolor (want true color RGB with values of 0 to 1)
icon1 = ind2rgb(img1,map1);
icon2 = ind2rgb(img2,map2);
% Get hiddenhandle of the toolbar we want to append to. By default the 'Figure Toolbar' is the only one active
% and should be listed last assuming a new, blank figure. Use 'figure; allchild(gcf)' to show all children
hToolbar=findall(gcf, 'type', 'uitoolbar'); %hToolbar=allchild(hFig); hToolbar=hToolbar(end);
%% for Seperate property editor and plot browser buttons
% % Add a new uipushtool to the end of the toolbar.
% uipushtool(hToolbar,'CData',icon1,...
% 'TooltipString','Property Editor',...
% 'ClickedCallback','propertyeditor',...
% 'Separator','on',...
% 'HandleVisibility','off');
% % Add a new uipushtool to the end of the toolbar.
% uipushtool(hToolbar,'CData',icon2,...
% 'TooltipString','Plot Browser',...
% 'ClickedCallback','plotbrowser',...
% 'Separator','off',...
% 'HandleVisibility','off');
%% for a single toggle that opens/closes the previous state of the plot tools (use view menu to show/hide plot/browser/editor)
'TooltipString','Property Editor',...
Take and go forth!!
Also see for more info and customizations:
Good Luck

Community Treasure Hunt

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

Start Hunting!