Creating a histogram using custom data

Let's consider the following simple data set

data = {{0,1.48},{1,0},{2.3,6.22},{3.1,0.01},{3.45,2.66},{5.34,0.11},
{7.98,3.18},{8.12,4.11},{8.32,0},{9.65,3.56},{10,5.22}};

The list contains pairs $$(x,y)$$. I want to use this data for creating a histogram where the $$x$$ values are the horizontal values of the histogram, while the corresponding $$y$$ values indicate the height of the respective bar of the histogram. I also should be able to control the width of the bars, let's say to be equal to 0.001.

Any suggestions on how to create the desired histogram?

• are the x values mid-points of bins or bin widths? – kglr Jun 18 at 9:09
• @kglr Well, the x values are the central values of the bins. However, I need to be able to control the width of the bin, let's say to be equal to 0.001. – Vaggelis_Z Jun 18 at 9:14
• related : Histogram based on pre-binned data – kglr Jun 18 at 9:33
• @kglr ListPlot is not what I want. What I want is a real histogram where I can control the width of the boxes. – Vaggelis_Z Jun 18 at 9:41
• You don't have a histogram. A histogram is constructed from "counts" from a sample of observations. There is no evidence that the $y$ values are related to counts in any way. Also, if the bins are already chosen, you certainly can't create smaller bin widths. Are the heights related to frequencies or means or what? – JimB Jun 18 at 15:24

Just convert your data to WeightedData with WeightedData @@ Transpose[data]:

Histogram[WeightedData @@ Transpose[data], 10]
• What is the purpose of 10 inside the histogram commend? – Vaggelis_Z Jun 18 at 10:36
• That just tells Histogram how many bins to use. You can specify the bins in a variety of ways. Automatic will leave Histogram to figure it out for you, but it doesn't always do a very good job. Specifying an integer like 10 tells it to use 10 bins. If you want to specify the bin width explicitly, you can use {width} (e.g., {1} for bins 1 unit wide). – Sjoerd Smit Jun 18 at 10:45

width = 0.1;
{x, y} = Transpose@{{0, 1.48}, {1, 0}, {2.3, 6.22}, {3.1,
0.01}, {3.45, 2.66}, {5.34, 0.11}, {7.98, 3.18}, {8.12,
4.11}, {8.32, 0}, {9.65, 3.56}, {10, 5.22}};

Graphics[{Lighter@Blue,
Table[Rectangle[{x[[i]], 0}, {x[[i]] + width, y[[i]]}], {i,
Length@x}]}, Frame -> True] Or

width = 0.1;
data = {{0, 1.48}, {1, 0}, {2.3, 6.22}, {3.1, 0.01}, {3.45,
2.66}, {5.34, 0.11}, {7.98, 3.18}, {8.12, 4.11}, {8.32, 0}, {9.65,
3.56}, {10, 5.22}};
Graphics[{Lighter@Blue,
Rectangle[{#1, 0}, {#1 + width, #2}] & @@@ data}, Frame -> True]