开发者

Common colorbar for scatter plots in Matlab with small numbers

开发者 https://www.devze.com 2023-03-03 20:02 出处:网络
I want to have each subplot share the same colorbar scale. I know caxis works for integers greater than 1, but there appears to be a problem using caxis with values such as 0.001.

I want to have each subplot share the same colorbar scale. I know caxis works for integers greater than 1, but there appears to be a problem using caxis with values such as 0.001.

 x = 0:1:10;
 y = 0:1:10; 
 z1 = .1:-.01:0;
 z2 = .01:-.001:0;

figure;
 subplot(1,2,1);
 scatter(x,y,10开发者_JAVA技巧,z1); colorbar;
 subplot(1,2,2);
 scatter(x,y,10,z2);  colorbar;

Common colorbar for scatter plots in Matlab with small numbers

Now I want to have the scatter subplots to have a common colorbar scale. I tried to use caxis, however I do not get the desired results. The left axis does not scale correctly, as they are all brown. How can this be corrected?

 ca = [0 .01];
 figure;
 subplot(1,2,1);
 scatter(x,y,10,z1); caxis(ca); colorbar;
 subplot(1,2,2);
 scatter(x,y,10,z2);  caxis(ca); colorbar;

Common colorbar for scatter plots in Matlab with small numbers


What you're seeing is the correct behaviour of caxis. When you set caxis([0 0.01]), all values greater than 0.01 are assigned the colour red (or brown, whatever you call it). In z1, all except the last point are greater than 0.01 and so they're all marked in red. If you tried caxis([0 0.1]), you'll see that the plot on the right is all blue.The dynamic range of your two subplots are an order of magnitude apart and so, you won't be able to represent both adequately with the same caxis limits.

Have you tried using a logarithmic color scale? Try the following:

subplot(1,2,1);
scatter(x,y,10,log10(z1)); colorbar;
caxis([-3 -1])

subplot(1,2,2);
scatter(x,y,10,log10(z2));  colorbar;
caxis([-3 -1])

Common colorbar for scatter plots in Matlab with small numbers

Does the above plot look better?

0

精彩评论

暂无评论...
验证码 换一张
取 消