2

I am trying to make a plot like this one:

enter image description here

I want a 2D histogram with bar color proportional to the height and semi-transparent bars. I tried to put together the examples provided here

x = randn(100, 2);

figure
hist3(x, [20 20]);


colormap(hot) % heat map
grid on
view(3);
%bar color
set(get(gca,'child'),'FaceColor','interp','CDataMode','auto');
%semitransparency
set(gcf,'renderer','opengl');

An example of the result is this:

enter image description here

The semi-transparency is absent.

I do not know if it is a problem of my Matlab version (R2014a) or if ---more probably--- I am messing up something. Maybe the axis handles?

Next Outside this question: I would also like to add a transparent surface interpolating the histogram values (I got also some problems with this). I think I saw something like this on SO recently, but I cannot find it anymore. Does anyone have some hits?

shamalaia
  • 2,282
  • 3
  • 23
  • 35

1 Answers1

2

You didn't actually change the surface transparency in your example. All you did was change renderers. Here's the extra line you would need:

set(get(gca,'child'),'FaceAlpha',0.8);

A value of 1 would be opaque, 0 invisible.

You may also want to change the edge line transparency too:

set(get(gca,'child'),'EdgeAlpha',0.2);
gnovice
  • 125,304
  • 15
  • 256
  • 359
  • I did try this. But with `set(get(gca,'child'),'FaceColor','interp','CDataMode','auto','FaceAlpha',0.5);` the bars has no color at all. Also, I do not understand how the mathworks example can work if `set(gcf,'renderer','opengl');` just changes the renderer – shamalaia May 03 '16 at 15:19
  • 2
    You need to change both the `FaceAlpha` property *and* set the renderer to `opengl`, since the OpenGL renderer is the only one that supports transparent rendering. – gnovice May 03 '16 at 15:26
  • sorry, I do not get it. did you try to run the code? If I do it the bars just don't have any color at all.. – shamalaia May 03 '16 at 15:36
  • If I run the code and add the first line from my answer, I get transparent, colored bars as expected. I'm running 2013a. You may want to check out your [`opengl` options](http://www.mathworks.com/help/matlab/ref/opengl.html) and see if different settings fix your problem. – gnovice May 03 '16 at 15:40