Bubbleplot produces a scatter plot that enables the visualization of up to 6-dimensional data. The dimensions used for displaying data include the X, Y and Z coordinates, the marker sizes, colors and shapes. The data types can be numerical or categorical (or strings). You can also label each point with a text annotation
This function works really well with clickableLegend, allowing you to highlight or hide/show groups of points in the bubble plot.
bubbleplot(x, y, z, siz, col, shape)
draws a 3D bubble plot. See input parameter description below.
bubbleplot(x, y, , siz, col, shape)
draws a 2D bubble plot.
enables you to pass in a cell array of strings to annotate each point
on the plot. By default the strings are displayed as text labels as well
as stored in the UserData property of the line objects
bubbleplot(..., textarray, 'ShowText', false)
will not display the text on screen, but will store it in the user
data property. This can be useful when creating a custom data tip.
[hLine, hText] = bubbleplot(...)
returns a vector of line handles to the points in the plot and
(if appropriate) a vector of handles to the text objects on the
The inputs should be vectors of the same length, with the following
Input Required Default-Value Type
x, y, z Yes N/A Numerical (Continuous or discrete)
siz No 8 Numerical (Continuous or discrete)
col No col = z Numerical or Categorical*
shape No 'o' Categorical* (upto 13 unique discrete values)
* "Categorical" variables can either be numeric with discrete values or
non-numeric data types that support a "UNIQUE" method. Examples of this
can be a cell array of strings, a nominal array or ordinal array.
* The siz variable is normalized to a marker size range of 3 to 20. To
specify a custom size range use the optional parameter
'markerSizeLimits'. Example: bubbleplot(..., 'MarkerSizeLimits', [5 32])
* The shape variable can also be a character that represents a marker
shape to be used for all points
* If col is a categorical variable, ensure it is integer-valued so that
it is handled correctly. If it is not integer valued, bubbleplot will
check to see if the number of unique values is less than 10% of the
length of the vector and use that to determine if the variable is
categorical. The colors used to depict categorical data are evenly
spaced (1 color level per unique category/label). However if col is
not categorical, its values are simply scaled to different values in
* The default font size used to display the text labels is 8 pt with a
left alignment. Use the input arguments 'FontSize' and 'Alignment' to
control these properties.
Example: bubbleplot(..., 'FontSize', 6, 'Alignment', 'center')
* You can specify a custom colormap using the Colormap argument. The
parameter can be a string (eg. 'cool'), a function handle (eg. @jet) or
an N-by-3 matrix of color RGB levels.
Example: bubbleplot(..., 'ColorMap', cmap)
Ameya Deoras (2020). Bubbleplot - Multidimensional scatter plots (https://www.mathworks.com/matlabcentral/fileexchange/48005-bubbleplot-multidimensional-scatter-plots), MATLAB Central File Exchange. Retrieved .
There is an issue when using the examples with clickableLegend: when changing the size of the markers for the legend this also change the size of a few of the markers in the plot. You can actually see this when carefully comparing the pictures in the examples before and after initiating the clickableLegend.
It has a problem with using 'ColorMap'. I found the solution that you have to modify the line 72 'error(nargchk(2,10,nargin,'struct'));' as 'error(nargchk(2,11,nargin,'struct'));'. Then, it works well.
You can run the example with 'h = bubbleplot(Horsepower, MPG, , Acceleration, Displacement, Origin,...
Mfg, 'fontSize', 6, 'ColorMap', @bone);'.
I can't seem to get the 'ColorMap' to work correctly. Can you add an example?
Nice work! is there any way to add transparency to the markers?
Very useful! But may still have a little problem. There is an error when using 'clickableLegend'.
I am looking for it