2010-12-17 14 views

Respuesta

2

supongo que la forma más fácil es dibujar el histograma primero y luego simplemente dibujar el cubo rojo sobre él.

A = randn(1,100); 
[n,xout] = hist(A); %# create location, height of bars 
figure,bar(xout,n,1); %# draw histogram 

dx = xout(2)-xout(1); %# find bin width 
idx = abs(xout-0.7) < dx/2; %# find the bin containing 0.7 
hold on;bar([xout(idx)-dx,xout(idx),xout(idx)+dx],[0,n(idx),0],1,'r'); %# plot red bar 
+0

gracias, pero estoy buscando una manera de t o dibujar en los histogramas .. – ariel

+1

@ariel: Parece que he cometido un error al llamar 'bar' sean. Ahora debería funcionar. – Jonas

+0

+1 y confirmó que funciona. – gnovice

6

Una alternativa a hacer dos parcelas de barras superpuestas como Jonas suggests es hacer una llamada a bar para trazar los contenedores como un conjunto de patch objects, a continuación, modificar el para cambiar el color de las caras de parche:

A = randn(1,100);     %# The sample data 
[N,binCenters] = hist(A);   %# Bin the data 
hBar = bar(binCenters,N,'hist'); %# Plot the histogram 
index = abs(binCenters-0.7) < diff(binCenters(1:2))/2; %# Find the index of the 
                 %# bin containing 0.7 
colors = [index(:) ...    %# Create a matrix of RGB colors to make 
      zeros(numel(index),1) ... %# the indexed bin red and the other bins 
      0.5.*(~index(:))];   %# dark blue 
set(hBar,'FaceVertexCData',colors); %# Re-color the bins 

Y aquí está la salida:

alt text

+0

ni siquiera comprobar que la serie de barras que dan mangos individuales después vi que un histograma sólo es un objeto único. +1 por ser más cuidadoso – Jonas

Cuestiones relacionadas