I plotted a histogram. I now trying to chang the way the x- axis is read.
The Data is huge so it currently reads 0, 200, 400, 800, 1000 Meanwhile i would like it to show the other bin sizes. my bin width is 5, therefore
I would like it to show 0, 5, 10, 15, 20..... 1000
I tried this hist(data(1:29196,1),[0:5:1000]);figure(gcf);
Thanks for any help received

 채택된 답변

Walter Roberson
Walter Roberson 2011년 8월 2일

3 개 추천

set(gca, 'XTick', 0:5:1000)
However, this seems likely to want to place the labels so closely together that they will become unreadable.
If your data is sufficiently large, there is a possibility that representing it all would require more space than you have available in your figure. There really isn't any effective way of dealing with that except for allowing more space for the axes, or providing a partially-visible uipanel with scroll bars (FEX contributions available) that shows the image at a higher resolution.

추가 답변 (1개)

the cyclist
the cyclist 2011년 8월 2일

0 개 추천

It would be helpful if you posted the code that generates the histogram, but I am guessing what you are asking for is this:
set(gca,'XTick',0:5:1000)
However, I don't think so many ticks are going to be legible. You might need to compromise.

댓글 수: 7

Anthony
Anthony 2011년 8월 2일
hist(data(1:29196,1),[0:5:1000]);figure(gcf);
Would like to know where exactly to place set(gca,'XTick',0:5:1000)
Walter Roberson
Walter Roberson 2011년 8월 2일
Right after the hist() call.
You should not need to figure() call unless have have done something unusual such as set(0,'CurrentFigure')
Walter Roberson
Walter Roberson 2011년 8월 2일
It looks to me as if probably you should instead be using
[b,bin] = histc(data(1:29196,1),0:5:1000);
bar(bin, b);
after that you might find you do not need to set the xtick.
Anthony
Anthony 2011년 8월 3일
I tried this and this is the error i get
[b,bin] = histc(data(1:29196,1),0:5:1000);
bar(bin, b);
??? Error using ==> bar at 57
X must be same length as Y.
the cyclist
the cyclist 2011년 8월 3일
Try it with the hist() function rather than the histc() function (which creates an extra bin because of how it handles edges). [You might want to define your bin centers as 2.5:5:997.5.]
Kelly Kearney
Kelly Kearney 2011년 8월 3일
Actually, I think Walter is misusing the outputs of histc:
edge = 0:5:1000;
[b,bin] = histc(data(1:29196,1), edge);
bar(edge,b,'histc');
is what I think he intended.
Walter Roberson
Walter Roberson 2011년 8월 3일
Yes, that would make sense, Kelly. This could be further reduced to
edge = 0:5:1000;
bar(edge, histc(data(1:29196,1),edge), 'histc')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by