- Undocumented Matlab - https://undocumentedmatlab.com -

Undocumented scatter plot behavior

Posted By Yair Altman On October 12, 2009 | 18 Comments

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.

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

18 Comments (Open | Close)

18 Comments To "Undocumented scatter plot behavior"

#1 Comment By Naor On October 12, 2009 @ 11:59

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.

#2 Comment By Yair Altman On October 12, 2009 @ 13:01

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.

#3 Comment By Venkat On October 12, 2009 @ 22:33

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?

#4 Comment By Yair Altman On October 13, 2009 @ 01:50

Venkat – Interesting question. Unfortunately, I do not know if it can be done or how.

#5 Comment By Sebastiaan On October 13, 2009 @ 06:08

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.


#6 Pingback By Performance: scatter vs. line | Undocumented Matlab On October 14, 2009 @ 08:01

[…] Charting Matlab’s unsupported hidden underbelly « Undocumented scatter plot behavior […]

#7 Comment By Boyan On March 26, 2010 @ 09:15

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…


#8 Comment By jacob On January 12, 2012 @ 01:53

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

#9 Pingback By Undocumented scatter plot jitter | Undocumented Matlab On June 6, 2012 @ 06:05

[…] You may also be interested in the article I posted a few years ago about another undocumented scatterplot behavior […]

Article printed from Undocumented Matlab: https://undocumentedmatlab.com

URL to article: https://undocumentedmatlab.com/articles/undocumented-scatter-plot-behavior

URLs in this post:

[1] Undocumented scatter plot jitter : https://undocumentedmatlab.com/articles/undocumented-scatter-plot-jitter

[2] Undocumented plot marker types : https://undocumentedmatlab.com/articles/undocumented-plot-marker-types

[3] Accessing hidden HG2 plot functionality : https://undocumentedmatlab.com/articles/hidden-hg2-plot-functionality

[4] Handle Graphics Behavior : https://undocumentedmatlab.com/articles/handle-graphics-behavior

[5] Performance: scatter vs. line : https://undocumentedmatlab.com/articles/performance-scatter-vs-line

[6] copyobj behavior change in HG2 : https://undocumentedmatlab.com/articles/copyobj-behavior-change-in-hg2

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.