# How Can I Change the Alignment of Histogram Bin Tick Labels?

Posted 8 years ago
10711 Views
|
6 Replies
|
1 Total Likes
|
 I'm building a Histogram that will eventually have integer data that looks approximately like this (but not generated randomly):data = RandomInteger[{1, 5}, 100];Histogram[data]I want the X-axis labels to be centred under the bin bars, because, for example, that first left-hand bar really is the count of 1's; there are no values between 1 and 2, and, looking to the right-hand side, there certainly are no values of 6. How can I align the X-axis tick labels so they are centred under each bar?Thanks in advanceBrad
6 Replies
Sort By:
Posted 8 years ago
 Jim,That is absolutely perfect! Thanks very much,Brad
Posted 8 years ago
 How about this: data = RandomInteger[{1, 5}, 100]; Histogram[data, {0.5, Max[data] + 0.5, 1}, Ticks -> {Table[x, {x, Min[data], Max[data], 1}], Automatic}] 
Posted 8 years ago
 Hi Jos,Thanks for this. But your solution deals with labels, not tick mark labels. Going back to my histogram, if you look at how the left-most bar is labelled below the x-axis, you'll see the values 1 and 2 are aligned with the very edges of the bar. But that first bar is a count of 1's (the data is all integers. So the number 1 should align with the middle of the bar.Put another way, I want the whole of the x-axis labelling shifted half a bar width to the right, and I want to drop the 6, because there are no values of 6 in my dataset.The other thing your solution does is affix the value as the label, not the bin from which it comes. So by implying your solution, effectively I am positioning the y-values, not the x-values, on my chart.
Posted 8 years ago
 Hi Brad,I assume shifting the mark label in hystogram is not possible. That's why I always play around with the Barchart labels for this type of plots. Sorry I can't help further.I suggest that this question should be answered by the Wolfram Support Team.Good luck........Jos
Posted 8 years ago
 Sorry, it appears my histogram got mangled in my earlier post. It appears...
Posted 8 years ago
 Hi Brad, I hope this will help. See attached examples in file BarChart.nb. data = RandomInteger[{1, 5}, 5]; BarChart[{data} , ChartElementFunction -> "GlassRectangle" , LabelingFunction -> (Placed[# "%", Center] &) , ChartLabels -> {"1", "2", "3", "4", "5"} , PlotRange -> {Automatic, 6} , Joined -> Automatic , PlotLabel -> Style["Test [%]", "Title", 20] , BaseStyle -> {FontFamily -> "Arial", FontWeight -> "Bold", FontSize -> 11} , ChartStyle -> 45]  Attachments: