Plotting Histograms in MATLAB - x-axis Labels Aligned with Tick Marks

In summary: Histogram example");In summary, the histogram in MATLAB plots bin values centered under the bars, while the histogram in the textbook plots them under the tick marks.
  • #1
Saladsamurai
3,020
7
I am having some trouble deciphering how to plot a histogram in MATLAB. My main problem is that I want the x-axis labels to line up with the tick marks. I do NOT want the labels centered and under the bars themselves.

I have been looking into the histc() function http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hist.html", but have not figured out how to make it plot properly (with bin-edge labels under tick marks).

Anyone know how to do this?
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Is there any particular reason why you want to offset the tick marks in this way?
 
  • #3
Hi shoehorn. Yes. That is how I think it should be presented :)
If 10 values fall between 20 and 25, then 20 should be the left mark and 25 should be the right mark and the column should rise up between the 2.

Like http://www.treeplan.com/BetterHistogram_20041117_1555.htm" except that I tried this procedure and it does not work reliably every time.

I don't know; I guess I must be insane. I have been looking online for hours. I am surprised that nobody else think that they should be plotted like this. I just checked my textbook's solution manual too and they draw them with the bin values centered under the bar. But that is ambiguous to me. Does that value represent the max or min of the interval? And why should one have to go looking for the interval size? Why should they have to calculate it? These are rhetorical questions of course... I just think that Plots should be crystal clear so the average bear can read them.
 
Last edited by a moderator:
  • #4
Can anyone confirm if this is even possible? Thanks!
 
  • #5
I did it in Excel for anyone who cares. It was a PITA, but worth it I think. I will post a guide on how to do it once I complete it.

MyHistogram.jpg
 
  • #6
hi...
histogram program will be there which i used...please try it
i=imread(image path);
[r,c]=size(i);
val=0:255;
scale=0:255;
for x=1:r
for y=1:c
val(i(x,y))=val(i(x,y))+1;
end
end
figure;
stem(scale,val);
 

Related to Plotting Histograms in MATLAB - x-axis Labels Aligned with Tick Marks

1. How do I plot a histogram in MATLAB?

To plot a histogram in MATLAB, use the histogram function. This function takes in the data to be plotted as its input, and automatically calculates and displays the histogram with appropriate bin sizes and labels.

2. How can I align the x-axis labels with the tick marks on a histogram in MATLAB?

To align the x-axis labels with the tick marks on a histogram in MATLAB, use the 'XTickLabelAlignment' property of the histogram object. Set this property to 'end' to align the labels with the end of the tick marks, or 'center' to center them.

3. Can I customize the labels on the x-axis of a histogram in MATLAB?

Yes, you can customize the labels on the x-axis of a histogram in MATLAB by using the 'XTickLabels' property of the histogram object. Set this property to a cell array of strings to replace the default labels with your own.

4. How do I change the font size of the x-axis labels on a histogram in MATLAB?

To change the font size of the x-axis labels on a histogram in MATLAB, use the 'FontSize' property of the histogram object. Set this property to the desired font size (in points) to change the size of the labels.

5. Is it possible to add a title and axis labels to a histogram in MATLAB?

Yes, you can add a title and axis labels to a histogram in MATLAB by using the title, xlabel, and ylabel functions. Simply pass in the desired text as a string to these functions to add a title and labels to the histogram.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
952
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
6K
  • High Energy, Nuclear, Particle Physics
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
10K
Back
Top