MATLAB: How to remove the bars without values in hist3

distributionhist3histogramMATLAB

I'm using the hist3 function to plot a data distribution. I would like to remove all the bars that are zero. Picture 1 (yellow) is the way I want my graph to look but at the moment it looks like picture 2 (blue) where it displays all bars which are zero. Is their an option to change this?
Thanks a lot!
Goal.PNG
Fault.PNG

Best Answer

Use histogram2() instead (req. 2015b or later).
% Instead of
hist3([x,y]);
%use
histogram2(x,y)
By default bars with 0 height are not drawn.
190613 200501-Bivariate histogram plot - MATLAB.jpg