Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common colorbar for scatter plots in Matlab with small numbers

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,z1); colorbar;
 subplot(1,2,2);
 scatter(x,y,10,z2);  colorbar;

ex1

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;

enter image description here

like image 995
Elpezmuerto Avatar asked May 09 '11 18:05

Elpezmuerto


People also ask

How do you color a scatter plot in Matlab?

scatter( x , y , sz , c ) specifies the circle colors. You can specify one color for all the circles, or you can vary the color. For example, you can plot all red circles by specifying c as "red" . scatter(___, "filled" ) fills in the circles.

What does an open circle on a scatter plot mean?

The scatter plot accepts continuous variables. It does not accept string variables. Unselected items are drawn as open circles and selected values are drawn as filled circles of either the default highlight color or the color used to code the data.

How do you plot a scatter matrix in Matlab?

Create X as a matrix of random data and Y as a matrix of integer values. Then, create a scatter plot matrix of the columns of X against the columns of Y . The subplot in the ith row, jth column of the figure is a scatter plot of the ith column of Y against the jth column of X .

Which function call will create the scatter plot?

scatter() and plt. plot() You can also produce the scatter plot shown above using another function within matplotlib. pyplot .


1 Answers

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])

enter image description here

Does the above plot look better?

like image 120
abcd Avatar answered Sep 20 '22 19:09

abcd