# How to produce ListPlot that samples a given distribution?

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 this

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.

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?

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}]


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]


• 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. – shivangi Apr 10 at 3:38
• @shivangi, I understand. I edited my answer with a possibility. – David Keith Apr 10 at 4:17
• Thank you so much! This is exactly what I was trying to do. – shivangi Apr 13 at 0:51