MATLAB Answers

35

What happened to the figure toolbar in R2018b? Why is it an axes toolbar? How can I put the buttons back?

Asked by MathWorks Support Team on 13 Sep 2018
Latest activity Edited by thosman
on 30 Sep 2019 at 14:07
In R2018b, tools such as the zoom, pan, datatip, etc are no longer at the toolbar at the top of the figure window. These buttons are now in an "axes" toolbar and only appear when you hover your mouse over the plot. How do I put the buttons back at the top of the figure window?

Tags

No tags entered yet.

Products


Release

No release entered yet.

6 Answers

Answer by MathWorks Support Team on 16 Aug 2019
Edited by MathWorks Support Team on 16 Aug 2019
 Accepted Answer

In the R2018b release, you can drag-to-pan and scroll-to-zoom in an axes without having to call any MATLAB functions or select any toolbar buttons. Most types of axes include a default set of built-in interactions, but you can customize them by setting the Interactions property of the axes. For more information about controlling chart interactivity, see the following link:
You can also return the tools to the figure toolbar using the "addToolbarExplorationButtons" function. See the below example:
surf(peaks)
addToolbarExplorationButtons(gcf) % Adds buttons to figure toolbar
You can also hide or remove the axes toolbar with the code below:
ax = gca;
ax.Toolbar.Visible = 'off'; % Turns off the axes toolbar
%or
ax.Toolbar = []; % Removes axes toolbar data
If you would like to ensure that figures always open with the tools in the toolbar and that axes never contain a toolbar, execute the following code:
set(groot,'defaultFigureCreateFcn',@(fig,~)addToolbarExplorationButtons(fig))
set(groot,'defaultAxesCreateFcn',@(ax,~)set(ax.Toolbar,'Visible','off'))
The above settings will be reset when MATLAB re-starts. To ensure that these settings are used even after MATLAB re-starts, place the above "set" commands in a startup.m file. The startup.m file, when placed on the MATLAB Path, is run during the program start-up process. For more information about startup.m files, see the following link:
UPDATE (8/15/19):
Thank you for all of your comments and proposals about the axes toolbar.
We have heard your feedback and worked with members of the community on ways to improve the axes toolbar experience. With R2019a we released several enhancements to the axes toolbar, including faster startup time, ability to hover directly over the toolbar to make it visible, and improved performance with dense surface data. Additionally, with R2018b Update 5 we have made performance improvements to the axes toolbar startup time. We will continue to develop enhancements to the axes toolbar experience, and would like to thank you again for your feedback to help us improve our products.
You can download the latest updates using the following link:

  23 Comments

Every time an improvement is made to a piece of software, some people will invariably complain.
So let me add my two cents.
This was a stupid, stupid change.
Please put the zoom tools back in the toolbar by default. Like everyone else on this forum, I used them all the time and I can't believe you hid them.

Sign in to comment.


Answer by Yair Altman on 10 Jan 2019
Edited by Yair Altman on 10 Jan 2019

For the benefit of readers who don't follow my blog, Michelle Hirsch posted the following comment yesterday, which sheds some light on the subject:
Rest assured the team is digging in to the feedback to figure out the best approach to addressing concerns.
One thing puzzles me about the whole conversation (esp. on MTLAB Answers). Nobody is mentioning the default axes interactions, which we introduced along with the axes toolbar. We actually felt this was the biggest breakthrough, because you don’t need to interact with the toolbar at all in order to zoom, pan, rotate, or add datatips to a chart. Any thoughts on this? There’s a huge banner on the figure in 18b that introduces these new gestures so we thought people would find them.
I also can clarify a couple of things from your post:
* The Toolstrip was not driven by the marketing guys (and gals!). It was very much driven by our interest in improving discoverability of key capabilities which were too buried in menus and toolbars.
* The axes toolbar was not created primarily to support the move to web graphics. We intended it to be a solution to multiple problems:
** The toolbar for a figure docked in the desktop can be very far from the figure itself.
** We’d like to move towards being able to define interactions at the axes level, instead of the figure level, since interactions are axes specific. The axes toolbar is one step in that direction

  6 Comments

Hello Yair,
Could you explain where the "huge banner on the figure in 18b is?" Is the banner perhaps something that appears the first time that Matlab is invoked after download, and then not again? Maybe no one is talking about the new features because they are effectively hidden.
At any rate, documentation by banner is not what most people would call good software practice.
And in this case the regular documentation of the phantom toolbar does not work either, for a different reason: it's inaccurate. If you go to "Interactively Explore Plotted Data" it says: "Some types of interactions are enabled by default, while other types of interactions are only available through the axes toolbar. The toolbar appears at the top-right corner of the axes when you hover over it."
This is not true. It only appears when you hover the cursor over the actual plot. Then, as i mentioned in a separate comment, if you take the cursor off the plot (still in the figure window but not on the toolbar) the toolbar disappears again, intentionally taking away any visual knowledge of whether any of the toolbar zoom states are active or not. That's poor.
I am yet to upgrade to 2018b but for my UI I'm hoping this will be a huge benefit. I have a complicated UI with multiple axis and controls. I wasted a lot of time trying to find work arounds to have different controls working on different images such as zoom. I'm hoping this change fixes this.
I feel that the change to controls being on the axis instead of the figure is long over due, not sure why there is such a big backlash.
Even in my complex GUI, with subplots, I don't want axis-specific controls. Just one button Zoom+ and I can zoom into all measurement channels. If I had to switch it on several times, this would be very annoying.
If someone wants axis-specific controls, make it an option to switch it on. But leave the old behaviour, because it is the most reasonable. Almost nobody likes the new one. Just leave it like it was before as default.
The fading-effekt is also very annoying. If somebody likes it, why not make it optional?

Sign in to comment.


Answer by Michael Montouchet on 25 Jun 2019

I am using a scatter3. It used to be very easy to rotate the things I display, now I have to use this command before being able to use the camera rotation:
addToolbarExplorationButtons(gcf)
It used to be simple.
Why is Matlab deleting nice features?
The reasons why Matlab is better than Python are the UI, the support, good documentation, user-friendlyness. Please continue this way and stop deleting what makes it easy. Otherwise, I would not see the point of using Matlab instead of Python.

  0 Comments

Sign in to comment.


Answer by Scott Nuccio on 26 Jun 2019
Edited by Scott Nuccio on 26 Jun 2019

Here is the best I have come up with. Thought I would share.
In my startup.m file I have the following line. They overwrite the new figure functions such that everytime you create a figure, the axes toolbar is removed and my script for adding the appropriate buttons to the figures toolbar is called.
try %#ok
if ~verLessThan('matlab','9.5')
set(groot,'defaultFigureCreateFcn',@(fig,~)figToolbarFix(fig));
set(groot,'defaultAxesCreateFcn',@(ax,~)set(ax.Toolbar,'Visible','off'));
end
end
My script for adding buttons to the toolbar is called 'figToolbarFix.m' and lives in my 'user -> documents -> matlab' folder with my 'startup.m' file.
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
addToolbarExplorationButtons(hFig)
% 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,...
'toolbox','matlab','icons','tool_plottools_show.png')),32);
[img2,map2] = imread(fullfile(matlabroot,...
'toolbox','matlab','icons','pageicon.gif'));
% 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)
uitoggletool(hToolbar,'CData',icon1,...
'TooltipString','Property Editor',...
'OnCallBack','plottools(''on'')',...
'OffCallBack','plottools(''off'')',...
'Separator','on',...
'HandleVisibility','off');
end
Take and go forth!!
Also see for more info and customizations:
Good Luck

  2 Comments

You could also consider these edits:
%in startup.m:
try %#ok
if ~verLessThan('matlab','9.5')
defaultFigureCreateFcn=@(fig,~)addToolbarExplorationButtons(fig);
% Using evalc ensures that you can group functions in a single
% anonymous function that otherwise have no output (as neither
% disableDefaultInteractivity() nor set() have output arguments).
defaultAxesCreateFcn=@(ax,~){...
evalc('set(ax.Toolbar,''Visible'',''off'')'),...
evalc('disableDefaultInteractivity(ax)')};
set(groot,'defaultFigureCreateFcn', ...
defaultFigureCreateFcn);
set(groot,'defaultAxesCreateFcn', ...
defaultAxesCreateFcn);
end
end
And/or:
%for use in functions you might need to share with others:
function fig=figure_legacy(varargin)
fig=figure(varargin{:});
try %#ok if verLessThan is missing verLessThan would have returned true
if ~verLessThan('matlab','9.5')
addToolbarExplorationButtons(fig)
% Use eval to trick the syntax checking in ML6.5 (both the ~ and
% the @ trip up the syntax checker).
%
% Using evalc ensures that you can group functions in a single
% anonymous function that otherwise have no output (as neither
% disableDefaultInteractivity() nor set() have output arguments).
defaultAxesCreateFcn=eval(['@(ax,~){',...
'evalc(''set(ax.Toolbar,''''Visible'''',''''off'''')''),',...
'evalc(''disableDefaultInteractivity(ax)'')}']);
set(fig,'defaultAxesCreateFcn', ...
defaultAxesCreateFcn);
end
end
end
A test of whether hToolbar is empty or not seems to be needed. I get frequent errors otherwise,
if ~isempty(hToolbar)
uitoggletool(hToolbar,'CData',icon1,...
'TooltipString','Property Editor',...
'OnCallBack','plottools(''on'')',...
'OffCallBack','plottools(''off'')',...
'Separator','on',...
'HandleVisibility','off');
end

Sign in to comment.


Answer by Bruno Luong
on 14 Sep 2019 at 14:43

Duplicate my poste here
For R2019b all the tricks found previously no longer work.
I found this one does the trick
set(groot,'defaultAxesCreateFcn', ...
@(ax,varargin) start(timer('StartDelay',1,'ExecutionMode','singleShot','TimerFcn',@(varargin) axtoolbar(ax,{}))));
You might put it in startup.m file
if ~verLessThan('MATLAB','9.7')
set(groot,'defaultAxesCreateFcn', ...
@(ax,varargin) start(timer('StartDelay',1,'ExecutionMode','singleShot','TimerFcn',@(varargin) axtoolbar(ax,{}))));
end

  1 Comment

Here are two additional ways to remove the toolbar in 2019b without timers. As mentioned elsewhere, place code for either method in your startup.m.
Method 1)
From playing around with removing the toolbar, I found that AxesCreateFcn method is no longer working as the cla(ax,'reset') is called after the axes is created (when hold is 'off' or the axes NextPlot property is "replace", which is the default). This resets the axes properties to their defaults (which appears to include the toolbar).
This method requires the axes to have hold on behavior by default, which bypasses the offending cla code path.
function SetDefaultFigureToolbar()
% Returns to pre-2018 style figures for all figures
%
% Note! This forces all axes to have hold 'on' by default
%
% Adds the toolbar back to the figure
% Removes the axes toolbar and interactions
% Set axes to be in hold 'on' mode by default
try %#ok
if ~verLessThan('matlab','9.5') % if matlab version >= 2018b
set(groot,'defaultFigureCreateFcn',@(fig,~)addToolbarExplorationButtons(fig));
set(groot,'defaultAxesCreateFcn', @axDefaultCreateFcn);
set(groot, 'defaultAxesNextPlot', 'add'); % default hold 'on' behavior
end
end
end
function axDefaultCreateFcn(hAxes, ~)
% On axes creation, remove the toolbar and interactions.
% From:
% https://undocumentedmatlab.com/blog/improving-graphics-interactivity
try
hAxes.Interactions = [];
hAxes.Toolbar = [];
catch
% ignore - old Matlab release
end
end
Method 2)
Removes the toolbar by making its default visible propery false. This method cannot remove interactions which have been shown to improve performance, but method 1 or the timer method by Bruno would allow for interaction update/removal.
set(groot, 'defaultAxesToolbarVisible', 'off')
Changes in default behavior
Finally, it is worth re-iterating that Method 1 changes default behavior by having hold on by default. Method 2 does not allow for adjustments to default interactions. Bruno's timer method should be able to accommodate both of these without changing matlab's default behavior.

Sign in to comment.


Answer by Tomoya Takeuchi on 4 Jan 2019

I put this lines in my startup.m
set(groot,'defaultFigureCreateFcn','addToolbarExplorationButtons(gcf)')
set(groot,'defaultAxesCreateFcn','set(get(gca,''Toolbar''),''Visible'',''off'')')

  2 Comments

Thank you Tomoya! This works great.
I like this disastrous feature: one click compared with hunting around the menus for a disastrous feature I use all the time to inspect my results. It's quick and easy and does the same thing every time.
the init code using GCF is buggy; scroll up to get unbuggy code

Sign in to comment.