Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me this question by using python!! 2 Scatter plots and histograms pi

ID: 3587429 • Letter: P

Question

Please help me this question by using python!!

2 Scatter plots and histograms pioieser in p 1. Create random points drawn from a bivariate normal distribution using, e.g, numpy.random.multivariate_ normal. Read up on how to use this function (http://doc org/doc/numpy/reference/generated/numpy. random.multivariate normal.html) s.SCi 2. Make a scatter plot of your random points. Save the plot as bivariate_scatter plot.pd:f 3. Make a histogram plot for thex and y coordinates. Save the histograms as bivariate_hist_x_plot.pdf 4. Make a single figure, called master_plot.pdf, showing the scatter plot in the top left corner, and bivariate_hist_y_plot.pdf the x histogram in the bottom left corner, and the y histogram in the top right corner. This should look something like figure 1 Put your commen ted code in a file called scatter_hist_plot.py 400 350 300 250 200 150 100 50 4 2 2 4 -4-3-2-1 0 1 2 3 4 -4-3-2-1 0 1 2 3 4 450 400 350 300 250 200 150 100 50 0 -4-3-2-1 0 1 2 3 4 Figure 1: Random points drawn from a bivariate normal distribution. Expected output: your code scatter_hist_plot.py should generate the four plots above when executed. The number of random points must be entered by the person running the code when it executes.

Explanation / Answer

Python code:
import numpy as objNp
import matplotlib.pyplot as objPlt
from matplotlib.ticker import NullFormatter

xObj = objNp.random.randn(1000)
yObj = objNp.random.randn(1000)
nullfmtObj = NullFormatter()

leftObj, widthObj = 0.1, 0.65
bottomObj, heightObj = 0.1, 0.65
bottom_h_Obj = left_h_Obj = leftObj + widthObj + 0.02
rect_scatter_Obj = [leftObj, bottomObj, widthObj, heightObj]
rect_histx_Obj = [leftObj, bottom_h_Obj, widthObj, 0.2]
rect_histy_Obj = [left_h_Obj, bottomObj, 0.2, heightObj]

objPlt.figure(1, figsize=(8, 8))
axScatterObj = objPlt.axes(rect_scatter_Obj)
axHistxObj = objPlt.axes(rect_histx_Obj)
axHistyObj = objPlt.axes(rect_histy_Obj)

axHistxObj.xaxis.set_major_formatter(nullfmtObj)
axHistyObj.yaxis.set_major_formatter(nullfmtObj)

axScatterObj.scatter(xObj, yObj)

binwidthObj = 0.25
xymaxObj = objNp.max([objNp.max(objNp.fabs(xObj)), objNp.max(objNp.fabs(yObj))])
limObj = (int(xymaxObj/binwidthObj) + 1) * binwidthObj
axScatterObj.set_xlim((-limObj, limObj))
axScatterObj.set_ylim((-limObj, limObj))
binsObj = objNp.arange(-limObj, limObj + binwidthObj, binwidthObj)
axHistxObj.hist(xObj, binsObj=binsObj)
axHistyObj.hist(yObj, binsObj=binsObj, orientation='horizontal')
axHistxObj.set_xlim(axScatterObj.get_xlim())
axHistyObj.set_ylim(axScatterObj.get_ylim())
objPlt.show()

Output:
Displays scatter and histogram