Question

In: Computer Science

Using Python, generate 100 random numbers ranging from 1 to 5, then plot them using matplotlib...

Using Python, generate 100 random numbers ranging from 1 to 5, then plot them using matplotlib or Seaborn as a histogram

Solutions

Expert Solution

Code:

import matplotlib.pyplot as plt
#importing matplotlib module
import random
#importing random module to generate random numbers

def plothist():
#creating a function to generate histogram

    number = [random.randint(1,5)for i in range(100)]
    #generating 100 random number in range of 1,5
  
    print(number)
    #printing the random numbers
    plt.hist(number)
    #ploting the histogram of the random numbers
  
    plt.show()
    #displaying the histogram
  
plothist()

Explanation:

We have used matplotlib to generate the histogram.

We have imported matplotlib and random modules in the program.

Then declared a function named "plothist()"

Then generated 100 random numbers between the range of 1 and 5

using .hist() we have generated a histogram of the random numbers

using .show() we displayed the histogram

Screenshot of the Code:

Screenshot of the Output:


Related Solutions

Generate 200 random numbers using each of the following continuous distributions and plot the histograms (a)...
Generate 200 random numbers using each of the following continuous distributions and plot the histograms (a) Uniform (use A = 3 and B = 7) (b) Exponential (use population mean = 0.2) (c) Gamma (use parameters 3 and 2) (d) Normal (use µ = 2 and σ = 5) Attach the histogram plots and reflect on what you observe. Hint: Use RAND() to generate uniform random numbers and use inverse CDF to generate random numbers for each distribution.
To generate 100 random numbers between 1-100 in a randomData.txt file To read the 100 random...
To generate 100 random numbers between 1-100 in a randomData.txt file To read the 100 random numbers from randomData.txt and store them in an array Print the data in the array Find the smallest and the largest of the random numbers and their array position Insert an element of value100 in the 51th position of the array Delete all the elements of the array having values between 50-80 and print the residual array Sort the data in the final array(residual)...
Generate 1000 random numbers from ??2, 5? starting with standard normal random numbers in R.
Generate 1000 random numbers from ??2, 5? starting with standard normal random numbers in R.
Assume that Z  (6). Generate 1000 random numbers from Z and plot the corresponding histogram.
Assume that Z  (6). Generate 1000 random numbers from Z and plot the corresponding histogram.
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
Write Java code to generate 100 random integers ranging from 0..9, inserting each element into an...
Write Java code to generate 100 random integers ranging from 0..9, inserting each element into an ArrayList. Then search for the first instance of the number 3, print the position, and then remove it from the list.
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data...
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data from a CSV file, which has no names, just numbers. All I did was to read a .csv file. How do I pull data from three columns which contains about 1500 rows with just numbers and make a scatter plot with two in the x-axis and the third in the y-axis?
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array to a temp array 3.) Call each of the methods to sort (bubble, selection, insertion, quick, merge), passing it the array 4.) In-between the calls, you are going to refresh the array to the original numbers. 5.) Inside of each sorting method, you are going to obtain the nanoseconds time, before and after the method Subtract the before time from the after time to...
Generate 1000 random numbers from a normal distribution with mean 1 and variance 2 using Box‐Muller...
Generate 1000 random numbers from a normal distribution with mean 1 and variance 2 using Box‐Muller transformation in R.
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT