I wanted to get a binned plot that a uniform background distribution with a spike at some bin. My first instinct was to use RandomVariate, and then ListPlot. What i get is thisenter image description here

This makes sense as the RandomVariate function is assigning a value to Y based on the distribution. But I was wondering how I would produce a plot that has a spike at some particular bin (some specified x). I would want to produce something that looks more like this, for example.

enter image description here

I know I could just manually enter the data, but is there a way to have a binned plot where there is a uniform background distribution and a gaussian peak at some specific x?


1 Answer 1


You are on the right track. Notice that in your mixture, the uniform distribution spans [0,2], but the Normal distribution has a mean of 3. Here is another mixture. Just adjust the distribution parameters as needed:

dist = MixtureDistribution[{1, 1},
    UniformDistribution[{0, 100}],
    NormalDistribution[50, 2]

Histogram[RandomVariate[dist, 1000], {1}]

enter image description here

Edit: If you want data, you can use some variant of HistogramList:

{binBoundaries, counts} = 
  HistogramList[RandomVariate[dist, 1000], {1}];

ListPlot[Transpose[{Most[binBoundaries], counts}], PlotRange -> All, 
 Filling -> Axis]

enter image description here

  • $\begingroup$ Yes, but this is a Histogram. The actual data will still have values between 0 and a 100. I wanted a way where the data itself is spread that way. $\endgroup$
    – shivangi
    Apr 10, 2019 at 3:38
  • $\begingroup$ @shivangi, I understand. I edited my answer with a possibility. $\endgroup$ Apr 10, 2019 at 4:17
  • $\begingroup$ Thank you so much! This is exactly what I was trying to do. $\endgroup$
    – shivangi
    Apr 13, 2019 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.