gradient of bubble colors in a bubble chart

14 ビュー (過去 30 日間)
SA-W
SA-W 2023 年 3 月 14 日
コメント済み: SA-W 2023 年 3 月 14 日
I want to create a bubblechart with three different bubble colors.
One group of bubbles is red, the second group is blue, and the color of the third group should be a mixture of red and blue. For instance, the left half of the bubble (circle) is red and the right half is blue. Or even better, a continuous trend from left to right.
Is there a way to do this?

回答 (1 件)

Cameron
Cameron 2023 年 3 月 14 日
I'm not sure what you mean by "continuous trend from left to right". Can you post an image of what you're looking for? This was what I thought you meant.
x = 1:30;
y = rand(1,length(x));
sz = rand(1,length(x));
%get color gradient from https://www.mathworks.com/matlabcentral/fileexchange/25536-red-blue-colormap
m = length(sz);
if (mod(m,2) == 0)
% From [0 0 1] to [1 1 1], then [1 1 1] to [1 0 0];
m1 = m*0.5;
r = (0:m1-1)'/max(m1-1,1);
g = r;
r = [r; ones(m1,1)];
g = [g; flipud(g)];
b = flipud(r);
else
% From [0 0 1] to [1 1 1] to [1 0 0];
m1 = floor(m*0.5);
r = (0:m1-1)'/max(m1,1);
g = r;
r = [r; ones(m1+1,1)];
g = [g; 1; flipud(g)];
b = flipud(r);
end
c = [r g b];
t = tiledlayout(1,1);
nexttile
b = bubblechart(x,y,sz,c,'MarkerEdgeColor','k');
colormap(c)
colorbar
blgd = bubblelegend('Population');
lgd = legend('My data');
blgd.Layout.Tile = 'east';
lgd.Layout.Tile = 'east';
  2 件のコメント
SA-W
SA-W 2023 年 3 月 14 日
Conceptually, I am looking for something similar as what was asked here. Instead of a rectangle, I want to fill a circle (bubble) with a gradient color.
You plotted a bubble chart where each bubble is filled with one color. I want a gradient color for a single bubble, not a constant color.
SA-W
SA-W 2023 年 3 月 14 日
Is it clear what I would like to have?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by