Gradient Colour Fill plot points (more complex plot)

21 views (last 30 days)
Hi everyone,
I seem to be having a problem plotting gradient dots. I believe my issue is quite similar to the following previous posts and probably others:
I used the following code:
markerSize = 15;
t5=threshold5_table.store_temporal_tle.Percentage; % all of the following are 32x1, double, values between 0-1
t10=threshold10_table.store_temporal_tle.Percentage;
t15=threshold15_table.store_temporal_tle.Percentage;
t20=threshold20_table.store_temporal_tle.Percentage;
t25=threshold25_table.store_temporal_tle.Percentage;
t30=threshold30_table.store_temporal_tle.Percentage;
plot(ones(1, numel(t5)), t5, '.', 'MarkerSize', markerSize);
set(gcf,'Color','w') % set the background of figure to white
hold on
plot(2 * ones(1, numel(t10)), t10, '.', 'MarkerSize', markerSize);
hold on
plot(3 * ones(1, numel(t15)), t15, '.', 'MarkerSize', markerSize);
hold on
plot(4 * ones(1, numel(t20)), t20, '.', 'MarkerSize', markerSize);
hold on
plot(5 * ones(1, numel(t25)), t25, '.', 'MarkerSize', markerSize);
hold on
plot(6 * ones(1, numel(t30)), t30, '.', 'MarkerSize', markerSize);
xlim([0 7])
ylim([0 1])
set(gca, 'XTick', [1 2 3 4 5 6], 'xTickLabel', {'5%','10%','15%','20%','25%','30%'},'FontSize',14,'FontWeight','bold');
...to plot the data:
My issue: I want to adjust the colour of the scatter 'filled' dots to reflect the amount of entries with the same scores, ie, in the first 5% plot, there are: 7 entries (0), 6 entries (1) and values between (0-1) are mostly single entries, but the colour doesnt show that. To keep things simple I'd like to plot all percentages in same colour (with gradient), if possible.
The example provided here https://uk.mathworks.com/help/matlab/ref/scatter.html (under opacity) seems quite similar. However, opacity is refering to the distance from zero. Im interested in the proportion of entries.
I believe I need to design a colormap? and then refer to the saved colormap here, in place of '???', but everything i've tried so far doesnt work with my code.
plot(ones(1, numel(t5)), t5, '.', 'MarkerSize', markerSize, 'Color', ???);
Any suggestions?
Thank you!
Vyte
  3 Comments
Vyte Jan
Vyte Jan on 12 Oct 2022
@DGM Interesting, thats good to know. And im assuming with scatter you cant plot points in a single line, because 'scatter' is literally in the name...
Vyte Jan
Vyte Jan on 12 Oct 2022
@DGM actually it has potential!
I changed my code slighty:
sz = 135;
scatter(ones(1, numel(t5)), t5, sz, '.');
scatter(ones(1, numel(t5)), t5, sz, '.');
set(gcf,'Color','w') % set the background of figure to white
scatter(2 * ones(1, numel(t10)), t10, sz, '.');
ylim([0 1])
xlim([0 3])
..and it seems to be working! I just need someones knowledge on how to design 'c' scatterplot (colormap) so that it would only be single color and I can substitute it in here:
c=
scatter(2 * ones(1, numel(t10)), t10, sz, c, '.');

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!