In [1]:
import numpy as np
import matplotlib.pyplot as plt
In [2]:
x = range(-3,4)
y = np.zeros(len(x))

print(x)
print(y)

for i in range(0,len(x)):
    y[i] = 2 - x[i]**2
    
plt.plot(x,y,'s-')
plt.show()
range(-3, 4)
[0. 0. 0. 0. 0. 0. 0.]
In [3]:
x = np.linspace(-3,3,10)
print(x)
y1 = 2 + np.sqrt(abs(x))
y2 = 2 + abs(x)**(1/3)

plt.plot(x,y1,'ms-')
plt.plot(x,y2,'ks-')
[-3.         -2.33333333 -1.66666667 -1.         -0.33333333  0.33333333
  1.          1.66666667  2.33333333  3.        ]
Out[3]:
[<matplotlib.lines.Line2D at 0x11579bba8>]
In [4]:
x = np.linspace(-4,4,100)
e = range(-1,4)

for i in e:
    y = x**i
    #plt.plot(x,y,label='y=x**%s' %i,linewidth=4)
    plt.plot(x,y,label='$y=x^{%s}$' %i,linewidth=4) # latex
    
plt.legend()
plt.xlim([x[0],x[-1]])
plt.ylim([-20,20])
plt.show()