Question

Histograms, Box Plots, and Violin Plots Q06.50 Plot the histogram of a normal distribution of 100 random numbers. Use NumPys

pls use codes that run in Jupyter notebook

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You can use Matplotlib library's, hist() function from pyplot module to draw a histogram easily. If you don't have it installed, simply write the following line in the command line: pip install matplotlib.

So here's the small code, you need to execute inside the jupyter notebook:

Code:

<start of code>

import matplotlib.pyplot as plt

import numpy as np

%matplotlib inline

mu = 20
sigma = 7

numbers = np.random.normal(mu, sigma, size=100)

plt.hist(numbers, 20)

plt.show()

<end of code>

That's all you need to write to get the histogram. So let me just brief you about the function and the arguments expected by those functions.

  1. The alias plt is commonly used for matplotlib's pyplot library.
  2. Similarly the alias np is used for numpy library.
  3. If using a Jupyter notebook, you need to include the line %matplotlib inline below the imports.
  4. Then we'll use numpy's np.random.normal() function to produce an array of random numbers with a normal distribution. The general format of the np.random.normal() function is:
    var = np.random.normal(mean, standard_deviation, size=<number of values>)
  5. Matplotlib's plt.hist() function produces histogram plots. The first positional argument passed to plt.hist() is a list or array of values, the second positional argument denotes the number of bins on the histogram. You can also pass additional arguments like denisty, histtype, alpha (opacity), etc.

AND HERE'S OUR OUTPUT:

5 10 15 20 25 30 35

IN CASE YOU WANT TO CHANGE THE TYPE OF HISTOGRAM, YOU CAN USE THE "histtype" PARAMETER LIKE: plt.hist(numbers, 20, histype='step'). Other types of histograms are - 'barstacked', 'stepfilled'.

IN THIS CASE THE OUTPUT WOULD BE LIKE:

Also, you can draw histograms using other libraries too like seaborn, numpy, etc. I myself prefer matplotlib. You can try out other ones too. But they are altogether similar. For instance, seaborn library actually uses matplotlib to draw plots.

Hope this helps. Best of luck!!

Add a comment
Know the answer?
Add Answer to:
pls use codes that run in Jupyter notebook Histograms, Box Plots, and Violin Plots Q06.50 Plot...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5 Random Numbers and Histograms [Applied] Let x = x1 + ... + x20, the sum...

    5 Random Numbers and Histograms [Applied] Let x = x1 + ... + x20, the sum of 20 independent Uniform(0,1) random variables. In R, create 1,000 simulations of x and plot their histogram. On the histogram, overlay a graph of the normal density function with the same mean as x. Comment on any differences between the histogram and the curve. Hint 1: To plot a histogram in R you can build on the following code: library(ggplot2) df <- data.frame( x...

  • Shown on the pages below are the normal quantile plots and histograms of three fast food restaura...

    Shown on the pages below are the normal quantile plots and histograms of three fast food restaurants that represent service times during dinner hours. The green vertical line in each histogram represents the mean, the red represents the median. Summary statistics for the three restaurants are also given. Compare and contrast the three restaurants service times as compared to a normal distribution. Write your answers in complete sentences. Write your answers on this page, below the summary statistics. Use additional...

  • only how to print the box plot choose between the two i already have all the...

    only how to print the box plot choose between the two i already have all the code except this one in java printBoxPlot - (Choice) A Method that displays an ASCII Representation of a box plot using the 5 Number Summary.   Write the program to display the results in a GUI. i.e. Create a Frame and two Panel's. In the top panel, display the statistics. In the bottom panel, draw the Box Plot Write a class called ArrayStats that has...

  • The following are short Python calculations. Give the answer and the Python code for each. 1....

    The following are short Python calculations. Give the answer and the Python code for each. 1. What is the sum of the numbers from 22:100 incrementing by 2? Do this in two ways: Use a while statement and a for loop to do the calculation. (Hint: make sure the numbers include 100) 2. What is the mean, standard deviation of the square root of the numbers from 3 to 5 incrementing by 0.1? Use the linspace function from the numpy...

  • Use the rbinom() function to create a vector of 1000 random observations from the binomial distribution...

    Use the rbinom() function to create a vector of 1000 random observations from the binomial distribution with n=100 and probability of success is equal to 0.4. Calculate the mean and standard deviation statistics for this vector of random draws using the mean() and sd() commands. How do these numbers compare the mean and standard deviation of the binomial distribution when  and ? If they are different, why? Make a histogram of this vector using the hist() command.

  • Python Programming language. Complete the problems below using Jupyter Notebook. Problem Needs to be solved from...

    Python Programming language. Complete the problems below using Jupyter Notebook. Problem Needs to be solved from number #1 link provided for the Data: -----> https://docs.google.com/spreadsheets/d/1TqhyxFKQlOHAyXpQBL-4C96kgZFBoMwUgE8-b33CqPQ/edit?usp=sharing PROBLEMS # 0.0 Import the libraries (pandas, matplotlib, and seaborn) Include the code line: %matplotlib inline #Include the code line: plt.style.use(“ggplot”) #Load the data using pandas #Inspect the data using head(), dtypes ANSWERD: import pandas as pd import matplotlib.pyplot as plt import seaborn as sns plt.style.use('ggplot') %matplotlib inline df = pd.read_csv() print(df.head()) print(df.dtypes) # 1...

  • 3. Generate a vector u with 100 elements randomly selected (uniformly) from 1 to 40. Then generat...

    3. Generate a vector u with 100 elements randomly selected (uniformly) from 1 to 40. Then generate a vector v with 100 elements randomly selected with a normal distribution of mean 20 and standard deviation 5 a) Write the vector to a file 'data.txt', using ,' as separator. (b) Remove the variable u (c) Scan the file and retrieve the variable u. (d) Print the 5-summary of the vector u (e) Plot the boxplot of u (f) Plot the histogram...

  • Plot a histogram 1 point Generate 10,000 normal random numbers with mean μ-0 and standard deviati...

    code in python 3 please Plot a histogram 1 point Generate 10,000 normal random numbers with mean μ-0 and standard deviation σ (the default). Plot them on a histogram with 25 bins Your submission should include a plot. Make sure to import matplotlib.pyplot as plt. Use plt.hist but not plt.show in your submission In order to obtain the histogram values for grading, please keep the form of the hist statement with the assignment below. Starter code (click to view) 1...

  • Instructions: If you require uniformly distributed random numbers in [0, 1], use Matlab’s built i...

    Instructions: If you require uniformly distributed random numbers in [0, 1], use Matlab’s built in uniform random number generator rand. Also, you may NOT use any Matlab built-in functions that explicitly perform the task asked for in the problem. Problem 6. Let α > 0 and set f(x)- ae-ale, for x e(-oo, oo). (a) Make a plot of f (b) Show that f is a probability density function (Hint: -, when z S 0, and x-r, when 0.) (c) If...

  • Please answer both 1 & 2. 1. Use Excel to generate 100 observations from the standard...

    Please answer both 1 & 2. 1. Use Excel to generate 100 observations from the standard Normal distribution. a.Make a histogram of these observations. How does the shape of this histogram compare with a Normal density curve? 2. Use Excel to generate 100 Normally distributed random values (that is 100 outcomes of a Normally distributed random variable with mean 10 and standard deviation of 5). a. Make a histogram for your data. How does the shape of this histogram compare...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT