apply colour bar colours to data points

1 view (last 30 days)
Gabriel
Gabriel on 15 Sep 2025
Answered: Star Strider on 15 Sep 2025
have made a hertzburg russel diagram, and want to overlay a color bar's colours onto my data points, and im not sure how. please advise.
my curret code:
data = readtable('hyg_v42.csv');
colorIndex = data.ci;
luminosity = data.lum;
valid = ~isnan(colorIndex) & ~isnan(luminosity);
colorIndex = colorIndex(valid);
luminosity = luminosity(valid);
figure;
scatter(colorIndex, luminosity, .25, 'Xcoulorbar');
set(gca, 'YScale', 'log');
xlabel('Colour Index (B-V)');
ylabel('Luminosity (L/L_\odot)');
title('Hertzsprung–Russell Diagram (HYG Database)');
grid on;
xlim ([-0.5 2.5])
ylim ([10^-5 10^10])
c=colorbar
c.Location="southoutside"

Answers (1)

Star Strider
Star Strider on 15 Sep 2025
The third and fourth arguments of scatter can control the size and colours of the plotted points. It is also necessary to define a colormap.
x = 0:10;
y = randn(size(x));
figure
scatter(x, y, 25, y, 'filled')
grid
colormap(turbo)
colorbar
A size argument of 0.25 might make the points too small to see.
.

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Tags

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!