Question: ======================================================================================================= Problem 3: Using matplotlib to create a graph Look at the code in the next two cells. It imports matplotlib and numpy in the

=======================================================================================================

Problem 3: Using matplotlib to create a graph

Look at the code in the next two cells. It imports matplotlib and numpy in the first, then generates a plot of four different functions in the second. The scale of the plot is specified on the first line as 0 to 10 with 100 random points generated. The scale can be adjusted above 10 for a wider/larger scale, or less than 10 for a smaller scale.

Run the code in both cells to view the graph. Then follow the instructions in subsequent cells. If you have trouble importing the libraries or cannot otherwise run the code to generate the graphs, open the HW#1 Emergency notebook to view them. Then return to this one to answer the questions below.

import matplotlib.pyplot as plt import numpy as np

# Code to generate a graph of various functions using matplotlib and numpy

n = np.linspace(0, 10, 100) # generate 100 sample points in range 1 to 10 - change the 10 to a different scale # Generate lines on the graph plt.plot(n, 8*n, label = '8n: linear') # graph a linear function plt.plot(n, 2*n**2, label = '2n**2: quadratic') # graph a quadratic function plt.plot(n, n**3, label = 'n**3: cubic') # graph a cubic function plt.plot(n, 2**n, label = '2**n: exponential') # graph an exponential function # Labels plt.title('textrbook: R3.1 - comparison plot of various growth functions') plt.legend() # Do it! plt.show()

Q1. copy and paste the graphing code from above, change the scale to 12, then rerun. What differences do you see in the generated functions compared with the first one whose scale only went to 10?

Q2. copy and paste the graphing code, change the scale to 20, then rerun. What differences do you see in the generated functions compared with the first two above?

Q3. copy and paste the graphing code, change the scale to 3, then rerun. What differences do you see in the generated functions compared with the ones above?

======================================================================================================= Problem 3: Using matplotlib to create a graph Look at the

tavtrhnnk- QY 1 - romnarienn nlnt of warinue arnuth functinne

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!