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

  • Context: MATLAB 
  • Thread starter Thread starter Saladsamurai
  • Start date Start date
  • Tags Tags
    Marks Matlab Plotting
Click For Summary

Discussion Overview

The discussion revolves around plotting histograms in MATLAB, specifically focusing on aligning x-axis labels with tick marks rather than centering them under the bars. Participants explore various methods and express their frustrations with existing solutions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks guidance on how to plot a histogram in MATLAB with x-axis labels aligned with tick marks, expressing dissatisfaction with the default behavior of centering labels under the bars.
  • Another participant questions the necessity of offsetting the tick marks in this manner.
  • A different participant describes their preferred method of plotting, where the left and right tick marks correspond to the bin edges, and expresses frustration with the ambiguity of centered labels in textbooks.
  • One participant asks for confirmation on whether aligning labels with tick marks is even possible in MATLAB.
  • Another participant mentions successfully creating a histogram in Excel, indicating they found it challenging but worthwhile, and plans to share a guide on the process.
  • A participant shares a MATLAB code snippet for a histogram program, suggesting it may help others in the discussion.

Areas of Agreement / Disagreement

Participants express differing views on the presentation of histogram labels, with no consensus on the best approach. Some agree with the need for clarity in plots, while others question the necessity of the proposed alignment.

Contextual Notes

The discussion includes varying assumptions about the representation of histogram data and the interpretation of tick marks, with no resolution on the effectiveness of the proposed methods.

Saladsamurai
Messages
3,009
Reaction score
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
Is there any particular reason why you want to offset the tick marks in this way?
 
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:
Can anyone confirm if this is even possible? Thanks!
 
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
 
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);
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
8K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 9 ·
Replies
9
Views
7K