shift horizontal histogram to right

I am trying to shift the entire histogram to right, i.e. at 0.04 instead of 0, without changing the xticks.

6 comentarios

Ameer Hamza
Ameer Hamza el 27 de Mzo. de 2020
Can you show an example output. How do you want to move distogram without moving the xticks.
Guillaume
Guillaume el 27 de Mzo. de 2020
Personally, I find this graph very confusing. What is the benefit of showing the histogram bars horizontally rather than vertically the way it's normally displayed?
And like Ameer, I certainly don't understand what that would mean for the bars of a histogram count/pdf/cdf/whatever to start at 0.4.
Mos_bad
Mos_bad el 27 de Mzo. de 2020
Actually, as you may see below, my final goal is to plot PDF of different set of data in horizontal direction at the same figure.
Ameer Hamza
Ameer Hamza el 27 de Mzo. de 2020
Do you want to show the pdf as bars or curves? For curves, it can be quite straightforward. For histograms, I couldn't think of a direct way. You will need to add several invisible axes and try to adjust their positions manually. Although possible, only try if it is necessary.
Image Analyst
Image Analyst el 27 de Mzo. de 2020
Would the waterfall plot be okay? Check out the waterfall function.
Mos_bad
Mos_bad el 27 de Mzo. de 2020
As the figure is 2D, waterfall doesn't work. What I wnt is 2D plot of the horizontal PDF curve for each column vector of dotted data.

Iniciar sesión para comentar.

 Respuesta aceptada

Adam Danz
Adam Danz el 27 de Mzo. de 2020
Editada: Adam Danz el 27 de Mzo. de 2020
Here's a demo that shows how to compute a probability density estimate for each column of data and how to plot the PDF curve next to each column of data. See inline comments for details.
% Produce a matrix of data where each column of y contains
% data for each vertical stack of dots with x-coordinates
% defined by x.
x = 0:5:50;
y = (randn(50, numel(x)) + linspace(.5,5,numel(x))) .* linspace(.5,2,numel(x));
% Plot the data
plot(x, y, 'bo')
% Compute the probability density estimates (pdfx) for each column of y
nSets = size(y,2);
nPoints = 1000;
points = linspace(min(y(:)), max(y(:)), nPoints);
pdfx = cell2mat(arrayfun(@(col){ksdensity(y(:,col),points)'}, 1:nSets));
% Compute the interval between the x-values
xInterval = mean(diff(x)); % ie, = 5
% Normalize results so that all pdf values are
% between 0 and 85% of the x-interval while maintaining
% the relative heights across all pdf curves.
pdfxNorm = (pdfx - min(pdfx,[],'all')) * (xInterval*.85/range(pdfx(:)));
% NOTE: if you want each pdf curve's height to be independent
% and *not* maintaining the relative hights across all pdf
% curves, use this line instead:
% pdfxNorm = (pdfx - min(pdfx,[],1)) .* (xInterval*.85./range(pdfx,1));
% Horizontally offset the pdfxNorm values so each column
% corresponds to an associated x-value.
pdfxShift = pdfxNorm - min(pdfxNorm,[],1) + x;
% Compute y-values for the pdf curves so that the
% curves do not extend beyond the range of the
% data within each column.
pdfYvals = repmat(points(:),1,size(pdfxShift,2));
pdfYvals(pdfYvals < min(y, [], 1) | pdfYvals > max(y, [], 1)) = NaN;
% Add PDFs to plot
axis tight
xlim([min(x), max(x)+xInterval])
hold on
plot(pdfxShift, pdfYvals, 'r-')
grid on
Here's an example of independent-height option for the pdfxNorm variable, using different random data.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Mzo. de 2020

Editada:

el 27 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by