Undocumented scatter plot behavior

One of my blog readers, Henrik Toft, reported an undocumented behavior of the well-known scatter plot function: scatter returns a handle to an hggroup-type object that contains child handles of the data points (patch-type objects). This enables easy manipulation of specific points (for example, changing the color or marker of interesting data points).

The undocumented behavior is that when the scatter plot contains more than 100 points, the returned hggroup object only has a single child – a handle to a unified patch object that contains all the data points. This prevents customization of specific points: color can be customized via the cdata property, but this is not trivial; the marker cannot be customized at all.

Both Henrik and I initially thought this was a simple bug. But when Henrik reported this issue to MathWorks support, he got the response that this is indeed the expected behavior (i.e., not a bug but a feature), which is not documented. MathWorks did not say whether this was because they didn’t think users need more than 100 child handles, or perhaps an issue with memory/performance. Whatever the reason, I feel that this behavior/feature should at least be documented:

>> hggroup = scatter(rand(99,1),rand(99,1));
>> size(get(hggroup,'Children'))
ans =
    99     1
 
>> hggroup = scatter(rand(100,1),rand(100,1));
>> size(get(hggroup,'Children'))
ans =
   100     1
 
>> hggroup = scatter(rand(101,1),rand(101,1));
>> size(get(hggroup,'Children'))
ans =
     1     1

Workaround: use the ‘v6′ option. Unfortunately, this option is deprecated and marked as obsolete by Matlab, with the warning that it will be removed in a future Matlab version. I hope this will not be done until a better workaround for the above-reported issue is implemented in the scatter function:

>> hPatches = scatter('v6',rand(101,1),rand(101,1));
Warning: The 'v6' argument to SCATTER is deprecated, and will no longer be supported in a future release.
> In usev6plotapi>warnv6args at 84
  In usev6plotapi at 40
  In scatter at 39
 
>> size(hPatches)
ans =
   101     1

If you have detected any other undocumented behavior, function or feature in Matlab, please report them in the comments section below, or directly by email to me: altmany at gmail dot com.

Related posts:

  1. Undocumented scatter plot jitter Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...
  2. Performance: scatter vs. line In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...
  3. Handle Graphics Behavior HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality. ...
  4. HG’s undocumented parameters interface Some HG functions also accept inputs parameters in a struct fields rather than the normal P-V pairs format. ...
  5. Controlling plot data-tips Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....
  6. ishghandle’s undocumented input parameter The built-in function ishghandle accepts a second input argument with the expected handle type....

Categories: Handle graphics, Medium risk of breaking in future versions, Stock Matlab function, Undocumented feature

Tags: , , ,

Bookmark and SharePrint Print

9 Responses to Undocumented scatter plot behavior

  1. Naor says:

    Interesting. I use scatter with thousands of points all the time. Perhaps I am misusing it then? I don’t really need the ability to access each data marker but scatter is just an easy function to work with.

    • Naor – Perhaps I should have been clearer: scatter works correctly even with 101+ data points, as you correctly said. However, the returned value in this case is simply a single patch handle rather than hundreds or thousands of separate data-point handles. If you don’t need to customize specific data points then this issue doesn’t really matter; but if you do need this ability, you need to use the obsolete ‘v6′ option.

  2. Venkat says:

    Hi Yair,
    In my GUI, I have to add/delete/adjust lot of graphs. In matlab compiler documentation, PLOTTOOLS is stated under List of Unsupported Functions.
    Is there any way to get PLOTTOOLS working with the compiled code of standalone EXE?

  3. Sebastiaan says:

    I do not like the method of using deprecated functions – they might just disappear the next release.

    I suggest using something like this:

    data = rand(227,2);
    hggroup(1) = scatter(data(1:100,1),data(1:100,2));
    hold on
    hggroup(2) = scatter(data(101:200,1),data(101:200,2));
    hggroup(3) = scatter(data(201:227,1),data(201:227,2));

    By default, it is plotted in different colours, but that can be easily overcome.

    Sebastiaan

  4. Pingback: Performance: scatter vs. line | Undocumented Matlab

  5. Boyan says:

    Hi
    This article has been very useful for me! I struggled few hours with this before I found this. Since I need to manipulate the individual points in a specific order it is worth noting that the order in, which the handle is returned with the ‘v6′ option is exactly the opposite of what the ‘Children’ property returns meaning that the first object is on top instead of on the bottom. I hope this helps to others and I have to say it is very disappointing Matlab decided to do this in such manner…

    Boyan

  6. jacob says:

    Thanks a lot! It took me quite a while to figure out why my functions suddenly stopped working.
    Again, thanks! you made my day.

  7. Pingback: Undocumented scatter plot jitter | Undocumented Matlab

Leave a Reply

Your email address will not be published. Required fields are marked *

*

<pre lang="matlab">
a = magic(3);
sum(a)
</pre>