In [9]:
import numpy as np
x = np.arange(0,100)
y = x*2
z = x**2
Out[9]:
In [3]:
import matplotlib.pyplot as plt
%matplotlib inline
Exercise 1¶
Follow along with these steps:
- Create a figure object called fig using plt.figure()
- Use add_axes to add an axis to the figure canvas at [0,0,1,1]. Call this new axis ax.
- Plot (x,y) on that axes and set the labels and titles to match the plot below:
In [10]:
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.plot(x,y)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('title')
Out[10]:
Exercise 2¶
Create a figure object and put two axes on it, ax1 and ax2. Located at [0,0,1,1] and [0.2,0.5,.2,.2] respectively.
fig = plt.figure()
ax1 = fig.add_axes([0,0,1,1])
- ax2 = fig.add_axes([0.2,0.5,.2,.2])
In [11]:
fig = plt.figure()
ax1 = fig.add_axes([0,0,1,1])
ax2 = fig.add_axes([0.2,0.5,.2,.2])
Now plot (x,y) on both axes. And call your figure object to show it.
- ax1.plot(x,y)
- ax1.set_xlabel('x')
- ax1.set_ylabel('y')
- ax2.plot(x,y)
- ax2.set_xlabel('x')
ax2.set_ylabel('y')
fig # Show figure object
In [13]:
fig = plt.figure()
ax1 = fig.add_axes([0,0,1,1])
ax2 = fig.add_axes([0.2,0.5,.2,.2])
ax1.plot(x,y)
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax2.plot(x,y)
ax2.set_xlabel('x')
ax2.set_ylabel('y')
#fig # Show figure object
Out[13]:
No comments:
Post a Comment