0% found this document useful (0 votes)
61 views1 page

Test - Generate - Figure3: Import Matplotlib - Pyplot As PLT Import Numpy As NP Import Matplotlib - Gridspec As Gs

The document outlines a procedure for generating a figure using Matplotlib in Python. It involves creating numpy arrays for linear, quadratic, and cubic functions of x, and plotting them in a 2x2 grid layout. The layout is adjusted for better visibility using 'plt.tight_layout()'.

Uploaded by

pavan developer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views1 page

Test - Generate - Figure3: Import Matplotlib - Pyplot As PLT Import Numpy As NP Import Matplotlib - Gridspec As Gs

The document outlines a procedure for generating a figure using Matplotlib in Python. It involves creating numpy arrays for linear, quadratic, and cubic functions of x, and plotting them in a 2x2 grid layout. The layout is adjusted for better visibility using 'plt.tight_layout()'.

Uploaded by

pavan developer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

3.

test_generate_figure3
Define a numpy array 'x' with expression '[Link](1, 101)'. Define another numpy array 'y1' with
expression 'y1 = x'.
Define another numpy array 'y2' with expression 'y1 = x∗∗2'.
Define another numpy array 'y3' with expression 'y1 = x∗∗3'.
Create a figure of size 8 inches in width, and 6 inches in height. Name it as fig.
Define a grid 'g' of 2 rows and 2 columns, using 'GridSpec' function. Ensure that '[Link]' is
imported, before defining the grid.

Create an axes, using [Link] function. Name it as axes1. The subplot must span the 1st row and 1st
column of the defined grid 'g'. Set 'title' argument to 'y = x'. Draw a line plot of 'x' and 'y1' using 'plot'
function on 'axes1.

Create an axes, using [Link] function. Name it as axes2. The subplot must span 2nd row and 1st
column of defined grid 'g'. Set 'title' argument to 'y = x∗∗2'. Draw a line plot of 'x' and 'y2' using 'plot'
function on 'axes2.

Create an axes, using [Link] function. Name it as axes3. The subplot must span all rows of 2nd column
of defined grid 'g'. Set 'title' argument to 'y = x∗∗3'. Draw a line plot of 'x' and 'y3' using 'plot' function on
'axes3.

Adjust the entire layout with the expression 'plt.tight_layout()'.

In [18]:
import [Link] as plt
import numpy as np
import [Link] as gs
x = [Link](1,101)
y1 = x
y2 = x**2
y3 = x**3
fig = [Link](figsize=(8,6))
g = [Link](2,2)
axes1 = [Link](g[0,0])
[Link](title="y = x")
[Link](x,y1)
axes2 = [Link](g[1,0])
[Link](title="y = x**2")
[Link](x,y2)
axes3 = [Link](g[:,1])
[Link](title="y = x**3")
[Link](x,y3)
plt.tight_layout()

You might also like