1

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!

4
  • Apologies i wrote normal in the title of this question but i meant uniform. Commented Mar 30, 2014 at 13:37
  • you can easily edit your question Commented Mar 30, 2014 at 13:53
  • I recommend finding a matplotlib tutorial for the plotting part; numpy.random can help with distribution modelling. But first of all, some general Python tutorial to get a hold of basic concepts/practices. Commented Mar 30, 2014 at 14:05
  • @Victoria There is also R language which is quite simple, designed for tasks like that. It includes also some Python frameworks that might interest you. Commented Mar 30, 2014 at 14:09

2 Answers 2

3

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)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

-1

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()

Image of Random Uniform Distribution drawn between range 0-5, with a sample size of 100

1 Comment

the x and y axes need to be swapped here

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.