Products & Services Solutions Academia Support User Community Company

Learn more about Statistics Toolbox   

hist3 - Bivariate histogram

Syntax

hist3(X)
hist3(X,nbins)
hist3(X,ctrs)
hist3(X,'Edges',edges)
N = hist3(X,...)
[N,C] = hist3(X,...)
hist3(...,param1,val1,param2,val2,...)

Description

hist3(X) bins the elements of the m-by-2 matrix X into a 10-by-10 grid of equally spaced containers, and plots a histogram. Each column of X corresponds to one dimension in the bin grid.

hist3(X,nbins) plots a histogram using an nbins(1)-by-nbins(2) grid of bins. hist3(X,'Nbins',nbins) is equivalent to hist3(X,nbins).

hist3(X,ctrs), where ctrs is a two-element cell array of numeric vectors with monotonically non-decreasing values, uses a 2-D grid of bins centered on ctrs{1} in the first dimension and on ctrs{2} in the second. hist3 assigns rows of X falling outside the range of that grid to the bins along the outer edges of the grid, and ignores rows of X containing NaNs. hist3(X,'Ctrs',ctrs) is equivalent to hist3(X,ctrs).

hist3(X,'Edges',edges), where edges is a two-element cell array of numeric vectors with monotonically non-decreasing values, uses a 2-D grid of bins with edges at edges{1} in the first dimension and at edges{2} in the second. The (i, j)th bin includes the value X(k,:) if

edges{1}(i) <= X(k,1) < edges{1}(i+1)
edges{2}(j) <= X(k,2) < edges{2}(j+1)

Rows of X that fall on the upper edges of the grid, edges{1}(end) or edges{2}(end), are counted in the (I,j)th or (i,J)th bins, where I and J are the lengths of edges{1} and edges{2}. hist3 does not count rows of X falling outside the range of the grid. Use -Inf and Inf in edges to include all non-NaN values.

N = hist3(X,...) returns a matrix containing the number of elements of X that fall in each bin of the grid, and does not plot the histogram.

[N,C] = hist3(X,...) returns the positions of the bin centers in a 1-by-2 cell array of numeric vectors, and does not plot the histogram. hist3(ax,X,...) plots onto an axes with handle ax instead of the current axes. See the axes reference page for more information about handles to plots.

hist3(...,param1,val1,param2,val2,...) allows you to specify graphics parameter name/value pairs to fine-tune the plot.

Examples

Example 1

Make a 3-D figure using a histogram with a density plot underneath:

load seamount 
dat = [-y,x]; % Grid corrected for negative y-values
hold on 
hist3(dat) % Draw histogram in 2D 

n = hist3(dat); % Extract histogram data;
                % default to 10x10 bins
n1 = n'; 
n1( size(n,1) + 1 ,size(n,2) + 1 ) = 0; 

Generate grid for 2-D projected view of intensities:

xb = linspace(min(dat(:,1)),max(dat(:,1)),size(n,1)+1);
yb = linspace(min(dat(:,2)),max(dat(:,2)),size(n,1)+1);

Make a pseudocolor plot:

h = pcolor(xb,yb,n1);

Set the z-level and colormap of the displayed grid:

set(h, 'zdata', ones(size(n1)) * -max(max(n))) 
colormap(hot) % heat map 
title('Seamount: ...
      Data Point Density Histogram and Intensity Map');
grid on 

Display the default 3-D perspective view:

view(3);

Example 2

Use the car data to make a histogram on a 7-by-7 grid of bins.

load carbig
X = [MPG,Weight];
hist3(X,[7 7]);
xlabel('MPG'); ylabel('Weight');

Make a histogram with semi-transparent bars:

hist3(X,[7 7],'FaceAlpha',.65);
xlabel('MPG'); ylabel('Weight');
set(gcf,'renderer','opengl');

Specify bin centers, different in each direction; get back counts, but don't make the plot.

cnt = hist3(X, {0:10:50 2000:500:5000});

Example 3

Make a histogram with bars colored according to height.

load carbig
X = [MPG,Weight];
hist3(X,[7 7]);
xlabel('MPG'); ylabel('Weight');
set(gcf,'renderer','opengl');
set(get(gca,'child'),'FaceColor','interp','CDataMode',...
'auto');

See Also

accumarray, bar, bar3, hist, histc

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS