# Combining a point plot with a histogram

Hi everyone and sorry for my english, I'm new to Mathematica. I have a problem combining points with histograms in Mathematica 12.0. I would like to display a frequency histogram along with points placed in the center of each bin. My ultimate goal is to put together a histogram with its Gaussian approximation. I tried using Show to display them together but the points are not centered in the bins and moreover the histogram is moved to the right. At this point, I would have another question to ask you: how can I create a Gaussian curve starting from Gaussian points (with ListLinePlot the graph is broken and I don't like it)? Here is the code of my attempt.

 istomax900 ={{0.0246604, 4}, {0.0258038, 3}, {0.0269472, 6}, {0.0280907,
14}, {0.0292341, 21}, {0.0303775, 14}, {0.0315209, 12}, {0.0326643,
10}, {0.0338078, 11}, {0.0349512, 6}}
gaussianamax900={{0.0246604, 1.57199}, {0.0258038, 3.60887}, {0.0269472,
6.88537}, {0.0280907, 10.9177}, {0.0292341, 14.3863}, {0.0303775,
15.7544}, {0.0315209, 14.338}, {0.0326643, 10.8445}, {0.0338078,
6.81618}, {0.0349512, 3.5606}}
Histogram[WeightedData @@ Transpose[istomax900], Length[istomax900]]
Show[ListPlot[gaussianamax900],
Histogram[WeightedData @@ Transpose[istomax900], Length[istomax900]]]

• People are less likely to help you if you do not provide code that other people can easily copy and paste. Don't force other people to retype your code. May 16, 2020 at 11:29
• ehm sorry , it's my first question. May 16, 2020 at 12:03
• It's fine, that's why I'm teaching you how things are done here. Does Histogram[WeightedData @@ Transpose[istomax900], Length[istomax900], Epilog -> {Red, Point[gaussianamax900]}] do what you want? May 16, 2020 at 12:05
• This allows me not to use "Show" but the points in the bins are not centered anyway May 16, 2020 at 12:17
• By "centered", do you mean the points are centered on the bars, or centered on the tops of the bars? May 16, 2020 at 12:20

Here are a few options for you to start. Try to experiment by reading examples in documentation for listed below functions.

data=RandomVariate[NormalDistribution[1,3],10^3];

f1=NormalDistribution[1,3];
f2=FindDistribution[data];

options={Filling->None,PlotStyle->PointSize[.02]};

Show[Histogram[data,20,"ProbabilityDensity",PlotTheme->"Detailed"],
DiscretePlot[PDF[f1,x],{x,-10.5,10.5},#]&@@options]

Show[Histogram[data,20,"ProbabilityDensity",PlotTheme->"Detailed"],
DiscretePlot[PDF[f2,x],{x,-10.5,10.5},#]&@@options]

Show[Histogram[data,20,"ProbabilityDensity",PlotTheme->"Detailed"],
DiscretePlot[PDF[f2,x],{x,-10.5,10.5},#]&@@options,
Plot[PDF[f2,x],{x,-9,9},PlotStyle->Opacity[.3]]]

Show[Histogram[data,20,"ProbabilityDensity",PlotTheme->"Detailed"],
Plot[PDF[f2,x],{x,-9,9}]]

• @kglr gave me the correct answer. Thank you for your availability May 16, 2020 at 12:49

Update: Using OP's data:

bincenters = istomax900[[All, 1]];
binwidth = First @ Differences[bincenters];
binspecs = {Min[#] - binwidth/2, Max[#] + binwidth/2, binwidth} & @ bincenters;

Show[Histogram[WeightedData @@ Transpose[istomax900], binspecs],
ListPlot[gaussianamax900, Joined -> True, PlotMarkers -> Automatic]]


SeedRandom[1]
data = RandomVariate[NormalDistribution[0, 1], 200];

histogram = Histogram[data];


You can extract the coordinates of bin centers and heights from histogram using Cases and use those points with ListLinePlot:

bincentersandheights = Cases[histogram , Rectangle[{xmin_, ymin_}, {xmax_, ymax_}, ___] :>
{Mean[{xmin, xmax}], ymax}, All];

Show[histogram, ListLinePlot[bincentersandheights,
PlotStyle -> Directive[Thick, Red], PlotMarkers -> "●"]]


Alternatively, you can use bincentersandheights to construct the desired points and lines to be used as Epilog:

Show[histogram,  Epilog -> ({Thick, Red, Line@#, PointSize[Large], Red, Point@#} &@
bincentersandheights)]


same picture

• Perfect. You have fully satisfied my request. Thank you very match. May 16, 2020 at 12:51
• @tommaso if kglr’s answer solves your problem, consider upvoting it and accepting it to reward their effort. May 16, 2020 at 14:51
• yes , sure. I click on the v, all right? May 16, 2020 at 15:06