Prev: plotyy and timeseries
Next: handling two figures in GUI
From: Bui Yuki on 31 Mar 2010 07:42 Hi Everyone, I have a problem with controlling color range in the colorbar. I tried several ways but couldn't find out the solution. Any helps would be greatly appreciated. A simple example of my problem is as follows. I want to plot the following graph: x=1:1:100; y=1:1:100; color=1:1:100; scatter(x,y,500,color,'.'); colorbar; If I plot image as above, the color will distribute linearly from 1-100. However, I need to specify the color in five ranges 0-20; 20-40; 40-60; 60-80; 80-100. Noted that the color may have random distribution, not only linear distribution as in my example. I tried to using colormap such as: x=1:1:100; y=1:1:100; color=1:1:100; scatter(x,y,500,color,'.'); caxis([0.0 100]); b = [ 0.0 1.0 1.0; 0.5 1.0 0.5; 1.0 1.0 0.0; 1.0 0.5 0.0; 1.0 0.0 0.0]; colormap(b); colorbar; Using this, I could plot the above image in five color ranges; the problem is that each range of color in the colorbar is not corresponding to my defined color range, i.e. 0-20; 20-40; 40-60; 60-80; 80-100. How could I fixed this problem? Bui
From: Oliver Woodford on 31 Mar 2010 08:00 "Bui Yuki" wrote: > > I have a problem with controlling color range in the colorbar. I tried several ways but couldn't find out the solution. Any helps would be greatly appreciated. > > A simple example of my problem is as follows. I want to plot the following graph: > x=1:1:100; > y=1:1:100; > color=1:1:100; > scatter(x,y,500,color,'.'); > colorbar; > > If I plot image as above, the color will distribute linearly from 1-100. However, I need to specify the color in five ranges 0-20; 20-40; 40-60; 60-80; 80-100. Noted that the color may have random distribution, not only linear distribution as in my example. > > I tried to using colormap such as: > x=1:1:100; > y=1:1:100; > color=1:1:100; > scatter(x,y,500,color,'.'); > caxis([0.0 100]); > b = [ 0.0 1.0 1.0; > 0.5 1.0 0.5; > 1.0 1.0 0.0; > 1.0 0.5 0.0; > 1.0 0.0 0.0]; > colormap(b); > colorbar; > > Using this, I could plot the above image in five color ranges; the problem is that each range of color in the colorbar is not corresponding to my defined color range, i.e. 0-20; 20-40; 40-60; 60-80; 80-100. > > How could I fixed this problem? > > Bui You have the data colored with 5 discrete colors, according to the range they're in. Isn't this what you want? I'm not clear about what you want. Do you want the colors to vary more gradually? If so you need to use a larger colormap, with more bins.
From: us on 31 Mar 2010 08:03 "Bui Yuki" <buihongha(a)gmail.com> wrote in message <hovcec$867$1(a)fred.mathworks.com>... > Hi Everyone, > > I have a problem with controlling color range in the colorbar. I tried several ways but couldn't find out the solution. Any helps would be greatly appreciated. > > A simple example of my problem is as follows. I want to plot the following graph: > x=1:1:100; > y=1:1:100; > color=1:1:100; > scatter(x,y,500,color,'.'); > colorbar; > > If I plot image as above, the color will distribute linearly from 1-100. However, I need to specify the color in five ranges 0-20; 20-40; 40-60; 60-80; 80-100. Noted that the color may have random distribution, not only linear distribution as in my example. > > I tried to using colormap such as: > x=1:1:100; > y=1:1:100; > color=1:1:100; > scatter(x,y,500,color,'.'); > caxis([0.0 100]); > b = [ 0.0 1.0 1.0; > 0.5 1.0 0.5; > 1.0 1.0 0.0; > 1.0 0.5 0.0; > 1.0 0.0 0.0]; > colormap(b); > colorbar; > > Using this, I could plot the above image in five color ranges; the problem is that each range of color in the colorbar is not corresponding to my defined color range, i.e. 0-20; 20-40; 40-60; 60-80; 80-100. > > How could I fixed this problem? > > Bui works as expected here (r2010a)... which ML ver do you have(?)... us
From: Bui Yuki on 31 Mar 2010 09:53 "Oliver Woodford" <o.j.woodford.98(a)cantab.net> wrote in message <hovdgm$nk9$1(a)fred.mathworks.com>... > You have the data colored with 5 discrete colors, according to the range they're in. Isn't this what you want? I'm not clear about what you want. Do you want the colors to vary more gradually? If so you need to use a larger colormap, with more bins. Oliver, I want to plot my data in 5 discrete colors, each color corresponds to a specific range of data. When I ran the following code: x=1:1:100; y=1:1:100; data=1:1:100; scatter(x,y,500,data,'.'); caxis([0.0 100]); b = [ 0.0 1.0 1.0; 0.5 1.0 0.5; 1.0 1.0 0.0; 1.0 0.5 0.0; 1.0 0.0 0.0]; colormap(b); colorbar; I could plot my data in 5 discrete colors, but I am not sure each color is corresponding to a specific data range. (I presume that when we use colormap with 5 colors as above, the data will automatically divided into five ranges, each range corresponds to 1 color). If we look at the colorbar in my example, you will see that each color is not corresponding to a specific data range. As for the above example, I want all data within [0-20] are plotted in [0.0 1.0 1.0] color, and all data value within [20-40] are plotted in [0.5 1.0 0.5] color , ..... In my example, the figure looks fine but the colorbar looks strange. Is it only the problem of the colorbar? Bui
From: Bui Yuki on 31 Mar 2010 10:02
> works as expected here (r2010a)... > which ML ver do you have(?)... > > us Hi us, Thanks for your reply. I am using Matlab 7.01. As I explained in my reply to Oliver, the figure looks fine; however, the colorbar is not. If the above code works well in Matlab(r2010a), my problem may be because of Matlab version. Bui |