# Mutiple colorbars for mutiple scatter plots in the same figure

14 views (last 30 days)
Ash4Matlab on 6 Jun 2022
Edited: Ash4Matlab on 6 Jun 2022
I want to make two pairs of scatter plots, for a total of four. Where each pair will be shown by a different color bar. I looked for help on the Internet, but I couldn't find the best way to get the results I need. The other pair of plots is not shown in my figure.That means there should one more pair of scatter plots whoch are symmetric to the plots shown and will represent the second colorbar. Below is my code
x1 = rand(1,150); x2 = rand(1,100); y1 = x1.^2; y2 = x2.^(1/2);
x3 = rand(1,150); x4 = rand(1,100); y3 = -x3.^2; y4 = -x4.^(1/2);
Conc = [y1 y2]; Conc2 = [y3 y4];
figure
ax1 = axes;
scatter([x1, x2],[y1, y2],40,Conc,'filled');
axis equal
hold on
ax2 = axes;
scatter([x3, x4],[y3, y4],40,Conc2,'filled');
axis equal
ax2.Visible = 'off';
ax2.XTick = []; ax2.YTick = [];
colormap(ax1)
colormap(ax2,'spring')
cb1 = colorbar(ax1,'Position',[0.1 0.1 0.05 0.815]);
cb2 = colorbar(ax2,'Position',[0.81 0.1 0.05 0.815]);
cb1.Label.String = 'Colorba1'; cb2.Label.String = 'Coloebar2';
cb1.Label.FontSize = 28; cb2.Label.FontSize = 28;
It will be a great help if anyone can put me in the right direction

Bjorn Gustavsson on 6 Jun 2022
Have a look at the file exchange contribution newcolorbar-multiple-colormaps-in-the-same-axes. It seems as it should let you do this.
HTH
Ash4Matlab on 6 Jun 2022
Edited: Ash4Matlab on 6 Jun 2022
My orignal plots are as you can see below is a result of four scatter plots. Where each pair of the petal shaped plots belong to one colorbar. That means I have four scatter plots, but I need two colorbars. I can generate the plots by
x1 = rand(1,150); x2 = rand(1,100); y1 = x1.^2; y2 = x2.^(1/2);
Conc = [y1 y2];
x3 = rand(1,150); x4 = rand(1,100); y3 = -x3.^2; y4 = -x4.^(1/2);
Conc2 = [y3 y4];
figure(1)
scatter([x1, x2],[y1, y2],40,Conc,'filled');
hold on
scatter([x3, x4],[y3, y4],40,Conc2,'filled');
Which will give me the following plot
As per you suggested I tired the follwing
x1 = rand(1,150); x2 = rand(1,100); y1 = x1.^2; y2 = x2.^(1/2);
Conc = [y1 y2];
x3 = rand(1,150); x4 = rand(1,100); y3 = -x3.^2; y4 = -x4.^(1/2);
Conc2 = [y3 y4];
figure(1)
scatter([x1, x2],[y1, y2],40,Conc,'filled');
colormap('parula')
colorbar('WestOutside')
hold on
cb2 = newcolorbar('EastOutside','color','blue');
scatter([x3, x4],[y3, y4],40,Conc2,'filled');
colormap(gca,'spring')
But I still have the same problem as before. That is I can not get the other pair of plots that belong to the colorbar on the east side. Please let me know if there is anyway to fix this.

### Categories

Find more on Annotations in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by