Show Sidebar Hide Sidebar

Bubble Charts in MATLAB

How to make a bubble chart in MATLAB. Examples of scatter charts whose markers have variable color, size, and symbols.

% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

x = 80 * randn(1, 30);
y = 80 * randn(size(x));
r = randi(1500, size(x));
c = randi(10, size(x));

fig = figure;

scatter(x, y, r, c, 'filled', 'MarkerEdgeColor', 'k')

%--PLOTLY--%

% strip = false => preserve MATLAB style!

response = fig2plotly(fig, 'filename', 'matlab-bubble-chart',  'strip', false);
plotly_url = response.url;
% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

trace1 = struct(...
  'x', [1, 2, 3, 4], ...
  'y', [10, 11, 12, 13], ...
  'mode', 'markers', ...
  'marker', struct(...
    'color', { {'hsl(0,100,40)', 'hsl(33,100,40)', 'hsl(66,100,40)', 'hsl(99,100,40)'} }, ...
    'size', [12, 22, 32, 42], ...
    'opacity', [0.6, 0.7, 0.8, 0.9]), ...
  'type', 'scatter');
trace2 = struct(...
  'x', [1, 2, 3, 4], ...
  'y', [11, 12, 13, 14], ...
  'mode', 'markers', ...
  'marker', struct(...
    'color', 'rgb(31, 119, 180)', ...
    'size', 18, ...
    'symbol', { {'circle', 'square', 'diamond', 'cross'} }), ...
  'type', 'scatter');
trace3 = struct(...
  'x', [1, 2, 3, 4], ...
  'y', [12, 13, 14, 15], ...
  'mode', 'markers', ...
  'marker', struct(...
    'size', 18, ...
    'line', struct(...
      'color', { {'rgb(120,120,120)', 'rgb(120,120,120)', 'red', 'rgb(120,120,120)'} }, ...
      'width', [2, 2, 6, 2])), ...
  'type', 'scatter');
data = {trace1, trace2, trace3};
layout = struct('showlegend', false);
response = plotly(data, struct('layout', layout, 'filename', 'bubblechart', 'fileopt', 'overwrite'));
plot_url = response.url
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.