Azzera filtri
Azzera filtri

Normalize a histogram to a different datasets, Normalize two histograms to their sum

16 visualizzazioni (ultimi 30 giorni)
Hi everyone,
i want to plot two datasets on the same histogram, however one group of the dataset represent cars going fast and the other group represent the slow ones, i want to plot both of them on the same histogram, but when i normalize it, it uses the number of observations for each group (e.g. if i have 100 fast cars and 15 slow cars it will be normalized (divided) according to 100 & 15), but i want both groups to be normalized to their sum = 115 vehicles so that the slow cars will appear in a tiny bars next to the fast ones. you can see the figure to make it more clear.
can anyone help me with that please?
thanks,
  4 Commenti
Adam Danz
Adam Danz il 31 Gen 2019
Instead of normalizing by dividing by 100 & 15, why not just divide by 115?
MJ
MJ il 31 Gen 2019
Modificato: MJ il 31 Gen 2019
I don't divide it manually by anything, i am telling how MATLAB does it, i am -in fact- looking for a way to divide by 115 (a user defined number let's say).

Accedi per commentare.

Risposta accettata

Adam Danz
Adam Danz il 31 Gen 2019
Modificato: Adam Danz il 31 Gen 2019
Idea 1
This is a little bit of a hack but you could add NaN values to each histogram input so that it has 115 elements. Then the probability normalization will normalize by n=115 rather than the number of non-nan datapoints. That would look something like this.
data = nan(1,115);
data(1:length(NBL2fsummary(:,4))) = NBL2fsummary(:,4);
NBL2fhistogram = histogram (data,'BinWidth',10,'Normalization','probability');
Idea 2
Use histcounts() and bar() instead of histogram() and normalize the data yourself. Pro: you're doing the normalization instead of using a black box. Con: you lose a lot of nice features that come with histogram().
It would look something like this:
n = histcounts(NBL2fsummary(:,4), edges); %you create the edges
m = histcounts(NBL2ssummary(:,4), edges);
count = sum([n,m]); %number of data points (used in normalization)
b2 = bar(edges(1:end-1), n/count, 'histc'); % n/count is the normalization
  3 Commenti
Adam Danz
Adam Danz il 1 Feb 2019
Nice work! I didn't look through the code but if you have any other questions I'd be glad to help.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by