2

I'm trying to make something like this:

enter image description here

A normalized histogram for a distribution with pdf or pmd plotted on it. The problem is that I could only use the distributions that are already in the python library for plotting this histogram. I want to have the same plot for my arbitrary discrete distribution that I defined. I was trying to use np.random.choice to make a sample array but the problem is that it is only useful if the array is small, otherwise, if we have a huge population it wont be useful.

import seaborn as sns
import numpy as np 
data = np.random.choice([10, 25, 34, 26, 44], size = 500, p = [0.1, 0.3, 0.5, 0.1, 0]) 
sns.distplot(data, norm_hist=True)

How could I define a function instead of writing an array and get random sample from that arbitrary function and then I could plot the sample as the way above? something like this:

random_sampling(lambda x: some function) and the output could be a sample that could be plotted using sns.distplot?

Community
  • 1
  • 1
Nikki
  • 195
  • 9
  • Give one or more examples of the function. – hpaulj Jan 16 '18 at 19:23
  • why not to plot the function directly without sampling? – Marat Jan 16 '18 at 19:26
  • Simple functions like: (exp(2*x)), (x**2), (2*x + 400),... that could be defined using lambda. – Nikki Jan 16 '18 at 19:27
  • I am looking for defining a function for the distribution that the samples are selected. I think I was vague explaining it above, the main population is a huge data set, and for sampling from that data set, I am trying to have an arbitrary function instead of having a distribution that is already in the python library. – Nikki Jan 16 '18 at 19:33
  • @N.Sh then is it correct to say you're looking for a way to obtain empirical pdf/cdf from a sufficiently large sample? – Marat Jan 16 '18 at 19:45
  • To be honest I am not really sure if that is the same. does the distribution function that the sampling is using impact the resulted pdf? – Nikki Jan 16 '18 at 19:54
  • 1
    Do you mean inverse transform sampling? https://stackoverflow.com/questions/21100716/fast-arbitrary-distribution-random-sampling – Georgy Jan 16 '18 at 20:34
  • I have seen topics that were on that matter but unfortunately it wasn't doing the function that I expected, I am hoping that I could have somehow a customized sampling of a huge data set and then plot the pdf of it, if that makes any sense? – Nikki Jan 16 '18 at 21:26
  • When you say "I am trying to have an arbitrary function instead of having a distribution that is already in the python library.", what do you mean by "distribution that is already in the python library"? – Georgy Jan 16 '18 at 23:09

0 Answers0