Can MATLAB plot a graph like this? (Ignore the black lines and light blue areas; I only care about the red and blue points.)

Hello everyone, I want to plot the image below. Please ignore the other parts; I'm mainly focused on the red and blue points. I know the scatter function can plot points of different sizes, but the issue is with the red legend next to it. Can MATLAB generate a legend like this, reflecting the size of the points? Looking forward to any responses.

 Accepted Answer

This is a bubble chart. You can create this in MATLAB using bubblechart
The legend isn't exactly the same, but conveys the relationship between size and value.

4 Comments

It seems that the bubblechart legend can have at most three bubbles. Is it possible to change this? I'd like to create a legend like the red one in the image above, made up of many continuously varying sized points.
The only way I can think to do that would be to manually create it yourself. Essentially, you'd create a second axes next to your plot and then plot the circle sizes you want positioned the way you want them.
% create dummy data
t = 0:0.1:10;
y = sin(t);
sz = (y+1)*50;
figure
scatter(t,y,sz);
ax1 = gca;
% create legend
ax2 = axes('Position',[ax1.Position(1)+ax1.Position(3)+0.005 ax1.Position(2) 0.05 ax1.Position(4)]);
scatter(ax2,0,1:100,1:100,'r')
ax2.YAxisLocation = 'right';
xticks(ax2,[])
yticks(ax2,0:20:100)
yticklabels(0:2:10)
ylabel('log_{10}Q')
Here's perhaps a slightly cleaner way.
% create dummy data
t = 0:0.1:10;
y = sin(t);
sz = (y+1)*50;
tiledlayout(1,11)
nexttile([1 10])
scatter(t,y,sz);
ax = nexttile;
scatter(0,1:100,1:100,'r')
ylabel('log_{10}Q')
ax.YAxisLocation = 'right';
xticks([])
% Customimze the displayed size (may not be necessary)
yticks(0:20:100)
yticklabels(0:2:10)

Sign in to comment.

More Answers (1)

Instead of bubble chart, try scatter where you can specify the color and size of each marker.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Release

R2023b

Asked:

on 3 Dec 2024

Commented:

on 5 Dec 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!