Linking marker face color to colorbar

37 views (last 30 days)
Hi
How do I link the face color of a marker to a colorbar? I have the following code so far:
plot(ones(length(cds_BD),1)*srs(1), v0_BD,'ks'), hold on
plot(ones(length(cds_GD),1)*srs(2), v0_GD,'ks')
plot(ones(length(cds_PRD),1)*srs(3), v0_PRD,'ks')
caxis([40 70]);
colorbar
Where "cds_**" and "srs" are defined arrays. Each entry in the matrix cds_** is linked to a initial velocity and I would like to color the marker's face with that color according to the colorbar.
Please help.
Thanks
  2 Comments
darova
darova on 13 Oct 2019
Can you attach some data? Image?
Christo van Rensburg
Christo van Rensburg on 13 Oct 2019
Hi
Find below the data:
cds_BD = [1.1105 1.3124 1.0474 1.0978 1.0852 1.0474 1.0221 1.0347 1.1988];
cds_GD = [0.8256 0.9615 0.9406 0.7524 1.0660 0.7838 0.8256 0.9301 0.7733];
cds_PRD = [0.9761 0.9964 0.9862 1.0472 0.9659 1.0066 0.9252 0.9151 0.9354];
v0_BD = [58.5101 58.2125 58.4750 62.5083 62.4396 62.3959 67.1816 66.3405 66.7731];
v0_GD = [61.1054 61.5469 61.4117 63.8668 64.1549 64.4764 66.8466 67.5859 67.2018];
v0_PRD = [61.6887 62.5646 62.5521 66.3803 65.8711 65.7790 69.4217 68.7722 68.5662];
So what I essentially want is to give each marker's face a color according to a colormap for a range of velocities.

Sign in to comment.

Accepted Answer

darova
darova on 13 Oct 2019
Try scatter
clc,clear
cds_BD = [1.1105 1.3124 1.0474 1.0978 1.0852 1.0474 1.0221 1.0347 1.1988];
cds_GD = [0.8256 0.9615 0.9406 0.7524 1.0660 0.7838 0.8256 0.9301 0.7733];
cds_PRD = [0.9761 0.9964 0.9862 1.0472 0.9659 1.0066 0.9252 0.9151 0.9354];
v0_BD = [58.5101 58.2125 58.4750 62.5083 62.4396 62.3959 67.1816 66.3405 66.7731];
v0_GD = [61.1054 61.5469 61.4117 63.8668 64.1549 64.4764 66.8466 67.5859 67.2018];
v0_PRD = [61.6887 62.5646 62.5521 66.3803 65.8711 65.7790 69.4217 68.7722 68.5662];
x0 = cds_BD*0;
h(1) = scatter(x0+1, v0_BD, [], cds_BD);
hold on
h(2) = scatter(x0+2, v0_BD, [], cds_GD);
h(3) = scatter(x0+3, v0_BD, [], cds_PRD);
hold off
set(h,'Marker','s')
set(h,'SizeData',50)
% caxis([40 70]);
colorbar
axis([0 4 55 70])
  2 Comments
darova
darova on 13 Oct 2019
Use this option to fill markers
set(h,'MarkerFaceColor','flat') % fill markers
Christo van Rensburg
Christo van Rensburg on 13 Oct 2019
Hi
It works perfectly, thanks so much darova!!

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!