![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175272/image.jpeg)
Can i adjust each thickness of each histogram bar of an image differently ? and can i plot or extract an exact value of the x axis in the histogram ?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to make the histogram of an Image but i want to focus on a specific zone ( around the value 2048 in the x axis) . So can i plot the histogram and adjust the bars so i can see clearly this value ? and i want the bars around this value to be narrower then the others .
Can anyone help me please because i have been trying without getting the result that i want. Thank you
0 Commenti
Risposte (2)
dpb
il 17 Ott 2016
Modificato: dpb
il 19 Ott 2016
The bar chart in Matlab is extraordinarily difficult to do anything with that's "out of the box".
To your specific question, the bars are a single object for each column so the width is a fixed single value for the series. The only way I can think to change this without writing something specific would be to use the ability of bar to treat NaN values as placeholders. To do this you would take the range of bins that are wanted to be different and substitute NaN for their values in one column and then do the obverse in a second vector--keep those values in their bins and replace all other with NaN. Then use bar twice, with hold on between the two calls and you'll have two bar plots on the same axes that can set the properties on to differentiate.
>> y=randn(1,1000); % sample data
>> [n,x]=hist(y,20); % get hist data
>> ix=[8:12]; % center bins to accentuate in histogram
>> n=[n; nan(size(n))]; % make second set same size
>> n(2,ix)=n(1,ix); % second is center section values
>> n(1,ix)=nan; % clear first center section (NaN)
>> hB=bar(x,n(1,:)); % outer portion normal bars
>> hold on % get ready to add center
>> hB(2)=bar(x,n(2,:),0.5); % with narrower bars
>>
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/175272/image.jpeg)
ADDENDUM Per the comment following IA's alternative, I did a File Exchange search and found <fileexchange/1420-scatterbar3> "SCATTERBAR3(X,Y,Z,WIDTH) draws 3-D bars of height Z at locations X and Y with width WIDTH."
ADDENDUM 2 Following up the discussion there wherein it (finally) dawns on me that 2D histogram is bogus, I think the solution you're looking for is
[n,x]=hist(YourImageArray(:),nBins);
and then follow the above example to emphasize chosen area(s).
2 Commenti
dpb
il 17 Ott 2016
You'll have to use hist3 and bar3 then, with the desired bins in the two dimensions set as above. I've got meetings; gotta' run so can't try to do a demo now but same idea should work with some extra effort to keep track of "who's who in the zoo" as far as intersecting bin locations.
Image Analyst
il 17 Ott 2016
As an alternative, if you want, you can color each bar independently, like you can make one particular bar red and the others blue, or whatever. Demo attached.
Vedere anche
Categorie
Scopri di più su Histograms 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!