Differences between figure and uifigure (R2025a onward)

49 次查看(过去 30 天)
Now that Java graphics are gone starting in R2025a, is there any strict distinction between figure() and uifigure()? Some default settings are different, but these can be easily changed later on. For example, one can enable handle visibility in a uifigure to use standard plot functions. Objects created with either function have the same class (matlab.ui.Figure), and it seems like various tools (such as exportapp) have been updated to support both.
The only difference I have found thus far is that figures have a new toolbar whereas uifigures retain a more minimalist form. Even after enabling Toolbar/Menubar in a uifigure, the result is closer to a more traditional MATLAB figure. Personally, I find the new figure toolbar hideous.
For some years now, the advice has been to use uifigures for "apps" and figures for plotting. If this is how figures are going to look from here on out, I will be doing everything in uifigures.

采纳的回答

Adam Danz
Adam Danz 2025-6-9
编辑:Adam Danz 2025-6-10
General purpose of uifigure and figure
Figures created using the figure function are configured for data exploration and visualization, while figures created using the uifigure function are configured for app building.
Difference between uifigure and figure
The difference between figures generated by uifigure and figures generated by figure has greatly decreased since R2016 when uifigure was released. As of R2025a, several key differences remain, hightlighted below.
See also the summary table in Differences Between Figures Created Using figure and uifigure in the documentation.
The figure toolstrip
Figures generated by the figure command display the new figure toolstrip (R2025a). The figure toolstrip is loaded with a lot of helpful features. If the toolstip is not desired, you can turn it off.
fig = figure(MenuBar="none");
However, this generates a figure outside of the new figure container environment thus opting-out of the performance enhancements delivered by the new environment. Toolstrip functionality such as plot edit mode and the property inspector will also not be available.
Current figure and HandleVisibility
Figures created using the figure command have HandleVisibility set to on and can therefore become the current figure by default (gcf), whereas figures created using uifigure have HandleVisibility set to off and cannot.
Docking behavior
Figures generated by uifigure are not docked to the figure container whereas figures generated by figure are. To generate a figure using the figure command that isn't docked to the figure container, set WindowStyle to normal.
figure(WindowStyle = "normal")
% alternatively,
figure(DockControls="off") % turns off ability to dock the figure
Additional information
Follow the Graphics and App Building Blog for an upcoming series of articles on this topic and please let us know if you're searching for any related information.
  8 个评论
Walter Roberson
Walter Roberson 2025-8-14
findall(groot, 'Type', 'figure')
allows getting handles to uifigure .
On the other hand, if you have several uifigure, it might not be obvious which one is which.
By the way, one way to tell a figure() from a uifigure() is to check to see whether double() of the figure handle is an integer. figure() that you create in your code default to having integer handles (but figures created on your behalf such as bode plot, might not have integer handles.)
Adam
Adam 2025-8-14
编辑:Adam 2025-8-14
Yeah,
fig=uifigure('HandleVisibility','on');
does work, but then if I'm in 'thinking mode' anyway to store the handle like that I don't need gca/gcf, I just have to remember that I can no longer just lazily do stuff like:
figure;
...
gcf
to access the figure I created before (or just clicked on to make it active), when I use a uifigure instead. A lot of these things just come down to having to change habits ingrained over almost 20 years of working with Matlab, so it takes a while!

请先登录,再进行评论。

更多回答(1 个)

the cyclist
the cyclist 2025-6-9
According to the Limitations section in the uifigure documentation, one cannot use the print() function on a uifigure.
  2 个评论
Dan Dolan
Dan Dolan 2025-6-9
That is interesting because another documentation page suggests that print can work on uifigures, and certainly seems to my Mac in R2025a. Either way, how does one determine if a given handle was created by figure or uifigure? Hypotehically, one could use try/catch blocks if there are commands that work on one type and fail on the other, but presumably MATLAB knows the answer behind the scenes. If nothing else, it has to know that figures can be docked into central container but uifigures cannot be.
Adam Danz
Adam Danz 2025-6-9
编辑:Adam Danz 2025-6-9
Thanks for pointing out the discrepancy beteween those documentation pages. Investigating.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by