apply colour bar colours to data points

7 visualizaciones (últimos 30 días)
Gabriel
Gabriel el 15 de Sept. de 2025
Respondida: Star Strider el 15 de Sept. de 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"

Respuestas (1)

Star Strider
Star Strider el 15 de Sept. de 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.
.

Categorías

Más información sobre Discrete Data Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by