Mutiple colorbars for mutiple scatter plots in the same figure
11 次查看(过去 30 天)
显示 更早的评论
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
hLink = linkprop([ax1,ax2],{'XLim','YLim','CameraUpVector','CameraPosition','CameraTarget'});
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;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1022890/image.png)
It will be a great help if anyone can put me in the right direction
0 个评论
回答(1 个)
Bjorn Gustavsson
2022-6-6
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!