필터 지우기
필터 지우기

Mutiple colorbars for mutiple scatter plots in the same figure

조회 수: 11 (최근 30일)
Ash4Matlab
Ash4Matlab 2022년 6월 6일
편집: Ash4Matlab 2022년 6월 6일
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;
It will be a great help if anyone can put me in the right direction

답변 (1개)

Bjorn Gustavsson
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
  댓글 수: 1
Ash4Matlab
Ash4Matlab 2022년 6월 6일
편집: Ash4Matlab 2022년 6월 6일
Thanks! for your help.
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by