import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-5,5,50)
y1 = 2*x + 1
y2 = x**2
plt.figure()
plt.plot(x,y1)
plt.show()
![这里写图片描述](https://img-blog.csdn.net/20180110151817417?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzgxNzY3Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
plt.figure(num=3,figsize=(8,6))
plt.plot(x,y2)
plt.plot(x,y1,color='red',linewidth=1.0,linestyle='--')
plt.show()
![这里写图片描述](https://img-blog.csdn.net/20180110152028613?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzgxNzY3Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
plt.figure()
plt.plot(x, y2)
plt.plot(x, y1, color='red', linewidth=1.0, linestyle='--')
plt.xlim((-1, 2))
plt.ylim((-2, 3))
plt.xlabel('x axis')
plt.ylabel('y axis')
new_ticks = np.linspace(-1,2,5)
print new_ticks
plt.xticks(new_ticks)
plt.yticks(new_ticks,[r'$apple$',r'$banana$',r'$pear$',r'$food\ food$',r'rice'])
plt.show()
[-1. -0.25 0.5 1.25 2. ]
<