画图:在区间[-2, 2]上画出y=x^2 和y=x^3 两条曲线
(1)两条曲线画在一张图上;(2)应用子图技术,把两条曲线分别画在水平排列的两张子图上。
import matplotlib.pyplot as plt
import random
x=[i/100-2 for i in range(400)]
y1=[x[i]**2 for i in range(400)]
y2=[x[i]**3 for i in range(400)]
plt.Figure()
plt.subplot(111)
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()
import matplotlib.pyplot as plt
import random
x=[i/100-2 for i in range(400)]
y1=[x[i]**2 for i in range(400)]
y2=[x[i]**3 for i in range(400)]
plt.Figure()
plt.subplot(211)
plt.plot(x,y1)
plt.subplot(212)
plt.plot(x,y2)
plt.show()