Oliver Amundsen
Oliver Amundsen

Reputation: 1511

Plot many horizontal Bar Plots in the same graph

I need to plot a x-y function, that shows the histograms at x-values. Something similar to the bottom plot of the next figure:

Set of vertical histograms

I tried to use matlab's "barh", but can't plot many in the same figure. Any ideas?

Or, maybe displacing the origin (baseline, basevalue in barseries properties) of successive plots would work. How could I do that for barh?

thanks.

Upvotes: 2

Views: 2097

Answers (1)

Shai
Shai

Reputation: 114786

Using 'Position' of axes property

% generate "data"
m = rand( 40,10 ); 
[n x] = hist( m, 50 );

% the actual plotting
figure; 
ma = axes('Position',[.1 .1 .8 .8] );  % "parent" axes
N = size(n,2);  % number of vertical bars
for ii=1:N, 
   % create an axes inside the parent axes for the ii-the barh
   sa = axes('Position', [0.1+(ii-1)*.8/N, 0.1, .8/N, .8]); % position the ii-th barh
   barh( x, n(:,ii), 'Parent', sa); 
   axis off;
end

enter image description here

Upvotes: 4

Related Questions