Histogram - problem with X axis (shifting the data)

6 visualizaciones (últimos 30 días)
Karolina
Karolina el 9 de En. de 2016
Respondida: Guillaume el 11 de En. de 2016
I plotted a histogram which represent three data: A, B, C. The A represent the sum of B+C. I think there is something wrong with X axis (they are shifted for every data), because the C data for some values is higher than A. Does anyone know what can be wrong in my code?
% Generate histogram
h0=histogram(C,'BinLimits',[0.00,3.00],'FaceColor',[0.8 0.8 0.8],'EdgeColor','none','FaceAlpha',1);
hold on
h1=histogram(A,'BinLimits',[0.00,3.00],'FaceColor',[0 0 0],'EdgeColor','none','FaceAlpha',1);
hold on
h2=histogram(B,'BinLimits',[0.00,3.00],'FaceColor',[0.3 0.3 0.3],'EdgeColor','none','FaceAlpha',0.7);
hold on
xlim([0.1,1.4]);
  2 comentarios
Image Analyst
Image Analyst el 9 de En. de 2016
What is your C data? Is it the counts you're talking about, or the bin edges?
Or is it the actual C, which you say is equal to A+B. If B is negative then C could be less than A for a particular element.
Karolina
Karolina el 11 de En. de 2016
My data are rasters. A represents a full extent od data. B and C are parts of A raster - that I why I wrote that B and C are the sum of A - but I did not summed the values. I want to represent the histogram o counts for A, B, and C. The C on my histogram is higher for positive values.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 11 de En. de 2016
My guess is that since you leave histogram to choose its own bins, your histograms don't have exactly the same bins. You can check the bins with:
h0.BinEdges %it would make more sense to call h0: hC
h1.BinEdges %it would make more sense to call h1: hA
h2.BinEdges %it would make a lot more sense to call h2: hB
If that is indeed the problem, either fix the bins to start with, or reuse the bins of the first histogram in the seconds and thid:
hC = histogram(C, 'BinLimits',[0.00,3.00],'FaceColor',[0.8 0.8 0.8],'EdgeColor','none','FaceAlpha',1);
hold on
hA = histogram(A, hc.BinEdges, 'BinLimits',[0.00,3.00],'FaceColor',[0 0 0],'EdgeColor','none','FaceAlpha',1);
hB = histogram(B, hc.BinEdges, 'BinLimits',[0.00,3.00],'FaceColor',[0.3 0.3 0.3],'EdgeColor','none','FaceAlpha',0.7);

Más respuestas (0)

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by