apply colour bar colours to data points

6 Ansichten (letzte 30 Tage)
Gabriel
Gabriel am 15 Sep. 2025
Beantwortet: Star Strider am 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"

Antworten (1)

Star Strider
Star Strider am 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.
.

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by