Exercise C: Matplotlib

Exercise C: Matplotlib#

2021-8-24

Matplotlib tutorials

# import numpy and matplotlib.pyplot using aliases np and plt

C.1 Basic plot#

# create an array x with 100 values between 0 and 2*np.pi
# create an array y=cos(x) using np.cos()
# plot x, y using plt.plot()
# add a legend "cos(x)" to the plot 

C.2 Scatter plot#

import numpy as np
np.random.seed(42)
X = np.random.multivariate_normal(mean=[0,0], 
                                  cov=[[1.0, 0.8],[0.8, 1.0]],
                                  size=200)
x = X[:,0]
y = X[:,1]
# Make a scatter plot of x and y using plt.scatter()
# Add a legend, title, xlabel and ylabel to the plot
# Change the color of the markers to green and the marker size to 2

C.3 Histogram#

# plot a histogram of y with 20 bins using plt.hist()