File Exchange

image thumbnail

Bubble

version 1.1.0 (8.21 KB) by Todd Baxter
Bubble/scatter plot with optional transparency.

2 Downloads

Updated 14 Apr 2020

View License

Usage:

P = bubble(X, Y)
P = bubble(X, Y, S)
P = bubble(X, Y, S, C)
P = bubble(___, 'PropertyName', Value, ...)
P = bubble(AX, ___)

Inputs:

X <1xN or Nx1 numeric vector>
- Specifies the x-location of the bubbles

Y <1xN or Nx1 numeric vector>
- Specifies the y-location of the bubbles

S (=[]) <1x1 numeric scalar or numeric vector with length N>
- Specifies the area of the bubbles in units of points squared
- If S is empty, then the default marker size will be used

C (=[]) <character array, 1x3 RGB triplet, numeric vector with length N, or Nx3 matrix of RGB triplets>
- If C is a character array of a color name or a 1x3 RGB triplet,
then all bubbles will have that same color
- If C is a vector with length N, then each bubble will be the color
in the current colormap of its corresponding linearly mapped value
- If C is an Nx3 matrix of RGB triplets, then each bubble will be the
color of its corresponding row
- If C is empty, then all bubbles will be the default color

AX <1x1 axes handle>
- Handle to axes where bubble plot is to be created

Optional property name/value pairs can be specified to control the
appearance and behavior of the patch object. See 'patch' and 'Patch
Properties' documentation for more details.

Outputs:

P <1x1 patch object handle>
- Additional properties 'XCenter', 'YCenter', and 'Size' can be used
to update the position and size of the bubbles

Description:

bubble was created to address the inability to make markers transparent
in the HG1 version of the 'scatter' plot function. While the HG2
version of the 'scatter' plot function does support transparent
markers, bubble still has a specific advantage.

bubble will properly display partial bubbles at the axes limits that
stay within the axes plotting region. The 'scatter' plot function will
either display the whole marker, which will spill out of the axes
plotting region, or it will not display a marker at all, even when a
partial marker extends into the axes plotting region.

Examples:

% create equally spaced bubbles of various sizes
x = reshape(repmat(1:5, 5, 1), 1, []);
y = reshape(repmat((1:5)', 5, 1), 1, []);
s = x * 500;
p = bubble(x, y, s, 'b');

% make the bubbles transparent and remove their edge/outline
set(p, 'FaceAlpha', 0.25, 'EdgeColor', 'none');

% change the position and size of the bubbles
x(1:2:end) = x(1:2:end) + 0.5;
y(1:2:end) = y(1:2:end) + 0.5;
s = fliplr(s);
set(p, 'XCenter', x, 'YCenter', y, 'Size', s);

% compare with 'scatter'
hold on;
h = scatter(x, y, s, 'r');
% show differences in displaying bubbles/markers at axes extents
set(gca, 'XLim', [1, 5.5], 'YLim', [1, 5.5]);

References:

http://undocumentedmatlab.com/blog/adding-dynamic-properties-to-graphic-handles
http://undocumentedmatlab.com/blog/ishghandle-undocumented-input-parameter

Cite As

Todd Baxter (2020). Bubble (https://www.mathworks.com/matlabcentral/fileexchange/74932-bubble), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

Updates

1.1.0

Improved bubble sizing robustness to changes in axes aspect ratio and camera view properties.

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux