I am a real beginner concerning coding and would like to know how to plot a uniform distribution between two points using python. Any help would be greatly appreciated!
2 Answers
This will do the work.
import numpy as np
import matplotlib.pyplot as plt
data = np.random.uniform(0,1,1000) # You are generating 1000 points between 0 and 1.
count, bins, ignored = plt.hist(data, 20, facecolor='green')
plt.xlabel('X~U[0,1]')
plt.ylabel('Count')
plt.title("Uniform Distribution Histogram (Bin size 20)")
plt.axis([0, 1, 0, 100]) # x_start, x_end, y_start, y_end
plt.grid(True)
plt.show(block = False)
Comments
You can use numpy.random.uniform(low=initial,high=final,size=size) for this type of distribution.
Initial and final are your parameters that define the limits of your distribution. You can specify the size of the distribution you want to generate also as a parameter within the function.
Hope that helps!
import numpy
import matplotlib.pyplot as plt
array = numpy.random.uniform(low=0,high=5,size=100)
plt.plot(array)
plt.show()
1 Comment
pep
the x and y axes need to be swapped here


matplotlibtutorial for the plotting part;numpy.randomcan help with distribution modelling. But first of all, some general Python tutorial to get a hold of basic concepts/practices.