2

I have a bivariate histogram plot created using bar3. I'm trying to change the color of the bars that have a height less than a certain threshold, but to no avail. I got this code:

h = bar3(dataSample, 0.5);
for n=1:numel(h)
     cdata=get(h(n),'zdata');
     set(h(n),'cdata',cdata,'facecolor','interp')
end

Current result

I can't figure out how to make the plot look like the one below, where the bars less than say 0.001 are gray:

Desired result

Any ideas?

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Oliver Amundsen
  • 1,491
  • 2
  • 21
  • 40

1 Answers1

1

here's how:

z=peaks(20);
h=bar3(z) 
for n=1:numel(h)
 cdata=get(h(n),'zdata');
 set(h(n),'cdata',cdata,'facecolor','interp')
end

colormap([0.5.*ones(128,3); parula(128)]);

enter image description here

I've arbitrarily decided to cut the colormap in the middle, first 128 intensities as gray the next 128 intensities in color. you can cut it however you want. You can find the threshold you want by setting the colormap binning (say to 256 bins) and the place in that partition below which it'll be gray.

bla
  • 25,846
  • 10
  • 70
  • 101
  • if you want to know more on how to create colormapw programatically see here: http://stackoverflow.com/questions/17230837/how-to-create-a-custom-colormap-programatically/17232355#17232355 – bla Mar 02 '17 at 22:57