Undocumented Matlab
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT

Getting default HG property values

February 13, 2013 7 Comments

All Matlab’s Handle Graphics (HG) property have default values. These values are used unless we specifically override the property value. For example, in R2012a, Matlab figure handles have 62 documented and 28 undocumented properties, all of which have some default value. When we create a new Matlab figure, we typically override only a handful of these properties.

How Matlab determines an HG property value
How Matlab determines an HG property value

For example, we might override the figure’s Name, NumberTitle, Position, Visible, Colormap and perhaps a few other properties. All the others are either read-only (i.e., un-settable), or left at their default values. This is also true for all HG objects: axes, images, plots, patches, uicontrols, annotations, Java control containers etc.
Matlab makes a distinction between factory and default values. Users can modify the default values, but not the factory values, which makes sense. In essence, user-specified property values override the default values, which in turn override the factory values. I find that this makes the process of using default values quite intuitive. I like this factory/default design.
Matlab has a dedicated doc page explaining how we can use, set and reset the default property values.
Unfortunately, MathWorks has not seen fit to explain how to get the full list of current default defaults, nor how to get the factory values. Today’s article provides the missing manual pages and completes the picture.

Accessing default and factory property values

To access any specific property’s default value, we need to compose a fictitious property name from the string ‘Default’ or ‘Factory’, followed by the object’s type (‘Figure’, ‘Axes’, ‘Line’ etc., as reported by the object’s Type property), and lastly the property name. For example: DefaultFigureColor or FactoryAxesUnits. As with all HG properties, these names are case insensitive. These fictitious properties all belong to Matlab’s root (0) handle.
We can now get and set the values of any of these fictitious properties (naturally, factory properties cannot be set):

>> get(0,'FactoryFigureUnits')
ans =
pixels
>> get(0,'FactoryFigureColor')
ans =
     0     0     0
>> get(0,'DefaultFigureColor')
ans =
                       0.8                       0.8                       0.8
>> set(0,'DefaultFigureColor','y');  % new figures will now have a yellow background color...
>> set(0,'DefaultFigureColor','factory');  % resets the default value to the factory value [0,0,0]=black

>> get(0,'FactoryFigureUnits') ans = pixels >> get(0,'FactoryFigureColor') ans = 0 0 0 >> get(0,'DefaultFigureColor') ans = 0.8 0.8 0.8 >> set(0,'DefaultFigureColor','y'); % new figures will now have a yellow background color... >> set(0,'DefaultFigureColor','factory'); % resets the default value to the factory value [0,0,0]=black

Note that since the default and factory property names are fictitious (i.e., dynamic properties that are parsed on-the-fly), they do not appear when you get(0), getundoc(0) or even uiinspect(0).
My uiinspect utility reports the factory values in its property-details panel, along with additional meta-data such as whether the properties are settable, readable etc.

uiinspect's 'Other properties' meta-data table
uiinspect's 'Other properties' meta-data table

Getting the full list of factory/default values

To get the long list of factory values, simply get a partial fictitious property name:

>> get(0,'factory')
ans =
                         factoryFigureAlphamap: [1x64 double]
                       factoryFigureBusyAction: 'queue'
                    factoryFigureButtonDownFcn: ''
                         factoryFigureClipping: 'on'
                  factoryFigureCloseRequestFcn: 'closereq'
                            factoryFigureColor: [0 0 0]
                        (... 655 additional properties ...)
>> get(0,'default')
ans =
               defaultTextColor: [0 0 0]
              defaultAxesXColor: [0 0 0]
              defaultAxesYColor: [0 0 0]
              defaultAxesZColor: [0 0 0]
          defaultPatchFaceColor: [0 0 0]
          defaultPatchEdgeColor: [0 0 0]
               defaultLineColor: [0 0 0]
    defaultFigureInvertHardcopy: 'on'
             defaultFigureColor: [0.8 0.8 0.8]
               defaultAxesColor: [1 1 1]
          defaultAxesColorOrder: [7x3 double]
          defaultFigureColormap: [64x3 double]
        defaultSurfaceEdgeColor: [0 0 0]
         defaultFigurePaperType: 'A4'
        defaultFigurePaperUnits: 'centimeters'
         defaultFigurePaperSize: [20.98404194812 29.67743169791]
          defaultFigurePosition: [200 200 560 420]
>> get(0,'DefaultAxes')
ans =
        defaultAxesXColor: [0 0 0]
        defaultAxesYColor: [0 0 0]
        defaultAxesZColor: [0 0 0]
         defaultAxesColor: [1 1 1]
    defaultAxesColorOrder: [7x3 double]

>> get(0,'factory') ans = factoryFigureAlphamap: [1x64 double] factoryFigureBusyAction: 'queue' factoryFigureButtonDownFcn: '' factoryFigureClipping: 'on' factoryFigureCloseRequestFcn: 'closereq' factoryFigureColor: [0 0 0] (... 655 additional properties ...) >> get(0,'default') ans = defaultTextColor: [0 0 0] defaultAxesXColor: [0 0 0] defaultAxesYColor: [0 0 0] defaultAxesZColor: [0 0 0] defaultPatchFaceColor: [0 0 0] defaultPatchEdgeColor: [0 0 0] defaultLineColor: [0 0 0] defaultFigureInvertHardcopy: 'on' defaultFigureColor: [0.8 0.8 0.8] defaultAxesColor: [1 1 1] defaultAxesColorOrder: [7x3 double] defaultFigureColormap: [64x3 double] defaultSurfaceEdgeColor: [0 0 0] defaultFigurePaperType: 'A4' defaultFigurePaperUnits: 'centimeters' defaultFigurePaperSize: [20.98404194812 29.67743169791] defaultFigurePosition: [200 200 560 420] >> get(0,'DefaultAxes') ans = defaultAxesXColor: [0 0 0] defaultAxesYColor: [0 0 0] defaultAxesZColor: [0 0 0] defaultAxesColor: [1 1 1] defaultAxesColorOrder: [7x3 double]

We can see that the defaults list is much shorter than the factory list. There are very few actual default overrides of the factory values. In fact, if we try to get the default value of a property that was not overridden (e.g., DefaultFigureNumberTitle), Matlab is smart enough to return the factory value (in this case, FactoryFigureNumberTitle=’on’).

Hidden properties

Hidden (undocumented) properties are not shown by default, but you can always access them directly, and their list can also be seen if we set the root handle’s HideUndocumented property:

>> get(0,'FactoryAxesLooseInset')
ans =
         0.13         0.11         0.095         0.075
>> get(0,'DefaultPatchLineSmoothing')
ans =
off
>> set(0,'DefaultLineLineSmoothing','on');  % default appears to be 'off' for Windows, 'on' for Macs
>> set(0,'HideUndocumented','off')
>> allPropDefaults = get(0,'factory');
>> length(fieldnames(allPropDefaults))   % 661 documented + 277 undocumented properties
ans =
   938

>> get(0,'FactoryAxesLooseInset') ans = 0.13 0.11 0.095 0.075 >> get(0,'DefaultPatchLineSmoothing') ans = off >> set(0,'DefaultLineLineSmoothing','on'); % default appears to be 'off' for Windows, 'on' for Macs >> set(0,'HideUndocumented','off') >> allPropDefaults = get(0,'factory'); >> length(fieldnames(allPropDefaults)) % 661 documented + 277 undocumented properties ans = 938

Factory values internals

For those interested in some internals, the factory values are stored (and can be accessed) via the object’s UDD reference, or rather the schema.prop reference of the properties (additional information on UDD properties can be found here). For example:

>> get(0,'FactoryFigurePosition')
ans =
   100   100   660   520
>> hProp = findprop(handle(gcf),'pos')
hProp =
	schema.prop
>> get(hProp)
            Name: 'Position'
     Description: ''
        DataType: 'figurePositionType'
    FactoryValue: [100 100 660 520]
     AccessFlags: [1x1 struct]
         Visible: 'on'
     GetFunction: []
     SetFunction: []
>> hProp.FactoryValue
ans =
   100   100   660   520

>> get(0,'FactoryFigurePosition') ans = 100 100 660 520 >> hProp = findprop(handle(gcf),'pos') hProp = schema.prop >> get(hProp) Name: 'Position' Description: '' DataType: 'figurePositionType' FactoryValue: [100 100 660 520] AccessFlags: [1x1 struct] Visible: 'on' GetFunction: [] SetFunction: [] >> hProp.FactoryValue ans = 100 100 660 520

Note that in this example, the FactoryFigurePosition value ([100 100 660 520]) is different than the DefaultFigurePosition value ([200 200 560 420]), which overrides it.

Conclusion

Setting default values enables easy setup of property values for all instances of an HG property in a Matlab session. It could be very tempting to add such setup to the startup.m file, so that such customizations automatically occur for all Matlab sessions. However, I strongly suggest against this: the moment you will try to run your application on any other computer or Matlab installation, you may find that your GUI/graphics look entirely different.
A much safer approach is to understand how these default values affect your application and then specifically set the desired property values in your m-code. This way, whatever the installation’s default values are, your application will always retain a consistent look-and-feel.
Have you found or ever used any interesting default or factory property value? If so, please share your experience in a comment.

Related posts:

  1. Handle object as default class property value – MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...
  2. Setting class property types – Matlab's class properties have a simple and effective mechanism for setting their type....
  3. Modifying default toolbar/menubar actions – The default Matlab figure toolbar and menu actions can easily be modified using simple pure-Matlab code. This article explains how....
  4. Plot LineSmoothing property – LineSmoothing is a hidden and undocumented plot line property that creates anti-aliased (smooth unpixelized) lines in Matlab plots...
  5. Property value change listeners – HG handle property changes can be trapped in a user-defined callback. ...
  6. Axes LooseInset property – Matlab plot axes have an undocumented LooseInset property that sets empty margins around the axes, and can be set to provide a tighter fit of the axes to their surroundings....
Handle graphics Hidden property Pure Matlab UIInspect Undocumented feature
Print Print
« Previous
Next »
7 Responses
  1. Nick February 18, 2013 at 07:17 Reply

    I’ve been wondering about these defaults for a while now. Thanks for posting this.

  2. Dan February 18, 2013 at 16:30 Reply

    It is not clear from your post, but you can also set default values of objects other than the root object. I often will generate a figure and then set its default values …

    hfig = figure;
    set(hfig, 'defaultAxesColorOrder', 'rgb');

    hfig = figure; set(hfig, 'defaultAxesColorOrder', 'rgb');

    so that all the axes on that figure have a custom value.

  3. Donn Shull February 20, 2013 at 11:23 Reply

    One interesting note is that handle graphic objects including root are sub classes of the abstract base class GObject. GObject defines 29 properties with 11 hidden properties. Sixteen of these properties have Factory values.

  4. Martin May 10, 2013 at 03:12 Reply

    Apart from get(0, ‘factory’) there’s (since MATLAB 2013a) the undocumented function rootfactoryvalues(), that also returns a structure with a lot of factory values. The list returned by the latter is much shorter, but contains values not returned by the former. I failed to see a pattern, but maybe someone else is more inclined to investigate further. 🙂

    Thanks for this interesting post! It improved my understanding of the MATLAB graphics system, which is one of my weaknesses.

  5. Creating high-quality graphics in MATLAB for papers and presentations | David Gleich: a notebook June 4, 2013 at 10:15 Reply

    […] are forgotten! Recently, the Undocumented Matlab Blog had a great post about these hidden defaultshttps://undocumentedmatlab.com/blog/getting-default-hg-property-values/. There are many other properties that can potentially be changed as […]

  6. Royi August 1, 2016 at 10:49 Reply

    Hi,

    Did they replaced the ‘0’ in get(0,'FactoryFigureColor') to ‘groot’ -> get(groot, 'FactoryFigureColor')?

    • Yair Altman August 1, 2016 at 10:57 Reply

      @Royi – no, get(0,'FactoryFigureColor') works just fine for me:

      >> get(0,'FactoryFigureColor')
      ans =
                0.94              0.94              0.94

      >> get(0,'FactoryFigureColor') ans = 0.94 0.94 0.94

Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre>
I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.

Click here to cancel reply.

Useful links
  •  Email Yair Altman
  •  Subscribe to new posts (feed)
  •  Subscribe to new posts (reader)
  •  Subscribe to comments (feed)
 
Accelerating MATLAB Performance book
Recent Posts

Speeding-up builtin Matlab functions – part 3

Improving graphics interactivity

Interesting Matlab puzzle – analysis

Interesting Matlab puzzle

Undocumented plot marker types

Matlab toolstrip – part 9 (popup figures)

Matlab toolstrip – part 8 (galleries)

Matlab toolstrip – part 7 (selection controls)

Matlab toolstrip – part 6 (complex controls)

Matlab toolstrip – part 5 (icons)

Matlab toolstrip – part 4 (control customization)

Reverting axes controls in figure toolbar

Matlab toolstrip – part 3 (basic customization)

Matlab toolstrip – part 2 (ToolGroup App)

Matlab toolstrip – part 1

Categories
  • Desktop (45)
  • Figure window (59)
  • Guest bloggers (65)
  • GUI (165)
  • Handle graphics (84)
  • Hidden property (42)
  • Icons (15)
  • Java (174)
  • Listeners (22)
  • Memory (16)
  • Mex (13)
  • Presumed future risk (394)
    • High risk of breaking in future versions (100)
    • Low risk of breaking in future versions (160)
    • Medium risk of breaking in future versions (136)
  • Public presentation (6)
  • Semi-documented feature (10)
  • Semi-documented function (35)
  • Stock Matlab function (140)
  • Toolbox (10)
  • UI controls (52)
  • Uncategorized (13)
  • Undocumented feature (217)
  • Undocumented function (37)
Tags
ActiveX (6) AppDesigner (9) Callbacks (31) Compiler (10) Desktop (38) Donn Shull (10) Editor (8) Figure (19) FindJObj (27) GUI (141) GUIDE (8) Handle graphics (78) HG2 (34) Hidden property (51) HTML (26) Icons (9) Internal component (39) Java (178) JavaFrame (20) JIDE (19) JMI (8) Listener (17) Malcolm Lidierth (8) MCOS (11) Memory (13) Menubar (9) Mex (14) Optical illusion (11) Performance (78) Profiler (9) Pure Matlab (187) schema (7) schema.class (8) schema.prop (18) Semi-documented feature (6) Semi-documented function (33) Toolbar (14) Toolstrip (13) uicontrol (37) uifigure (8) UIInspect (12) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
  • Nicholas (3 days 20 hours ago): Hi Yair, Thanks for the reply. I am on Windows 10. I also forgot to mention that this all works wonderfully out of the editor. It only fails once compiled. So, yes, I have tried a...
  • Nicholas (3 days 20 hours ago): Hi Yair, Thanks for the reply. I am on Windows 10. I also forgot to mention that this all works wonderfully out of the editor. It only fails once compiled. So, yes, I have tried a...
  • Yair Altman (4 days 4 hours ago): Nicholas – yes, I used it in a compiled Windows app using R2022b (no update). You didn’t specify the Matlab code location that threw the error so I can’t help...
  • Nicholas (5 days 0 hours ago): Hi Yair, Have you attempted your displayWebPage utility (or the LightweightHelpPanel in general) within a compiled application? It appears to fail in apps derived from both R2022b...
  • João Neves (8 days 4 hours ago): I am on matlab 2021a, this still works: url = struct(struct(struct(struct(hF ig).Controller).PlatformHost). CEF).URL; but the html document is empty. Is there still a way to do...
  • Yair Altman (11 days 3 hours ago): Perhaps the class() function could assist you. Or maybe just wrap different access methods in a try-catch so that if one method fails you could access the data using another...
  • Jeroen Boschma (11 days 6 hours ago): Never mind, the new UI components have an HTML panel available. Works for me…
  • Alexandre (11 days 7 hours ago): Hi, Is there a way to test if data dictionnatry entry are signal, simulink parameters, variables … I need to access their value, but the access method depends on the data...
  • Nicholas (11 days 21 hours ago): In case anyone is looking for more info on the toolbar: I ran into some problems creating a toolbar with the lightweight panel. Previously, the Browser Panel had an addToolbar...
  • Jeroen Boschma (15 days 4 hours ago): I do not seem to get the scrollbars (horizontal…) working in Matlab 2020b. Snippets of init-code (all based on Yair’s snippets on this site) handles.text_explorer...
  • Yair Altman (43 days 6 hours ago): m_map is a mapping tool, not even created by MathWorks and not part of the basic Matlab system. I have no idea why you think that the customizations to the builtin bar function...
  • chengji chen (43 days 13 hours ago): Hi, I have tried the method, but it didn’t work. I plot figure by m_map toolbox, the xticklabel will add to the yticklabel at the left-down corner, so I want to move down...
  • Yair Altman (51 days 6 hours ago): @Alexander – this is correct. Matlab stopped including sqlite4java in R2021b (it was still included in 21a). You can download the open-source sqlite4java project from...
  • Alexander Eder (57 days 1 hour ago): Unfortunately Matlab stopped shipping sqlite4java starting with R2021(b?)
  • K (63 days 12 hours ago): Is there a way to programmatically manage which figure gets placed where? Let’s say I have 5 figures docked, and I split it into 2 x 1, I want to place 3 specific figures on the...
Contact us
Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image
Undocumented Matlab © 2009 - Yair Altman
This website and Octahedron Ltd. are not affiliated with The MathWorks Inc.; MATLAB® is a registered trademark of The MathWorks Inc.
Scroll to top