import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1,1,100)
y1 = 2*x + 1
y2 = x**2
# 范围
plt.xlim((-1,2))
plt.ylim((-2,3))
# xy描述
plt.xlabel('X')
plt.ylabel('Y')
plt.plot(x,y1,color = 'red',linewidth = 1.0,linestyle = '--')
plt.plot(x,y2,color = 'blue',linewidth = 5.0, linestyle = '-')
plt.show()
new_ticks = np.linspace(-2,2,11)
print(new_ticks)
[-2. -1.6 -1.2 -0.8 -0.4 0. 0.4 0.8 1.2 1.6 2. ]
x = np.linspace(-1,1,100)
y1 = 2*x + 1
y2 = x**2
# 范围
plt.xlim((-1,2))
plt.ylim((-2,3))
# xy描述
plt.xlabel('X')
plt.ylabel('Y')
plt.plot(x,y1,color = 'red',linewidth = 1.0,linestyle = '--')
plt.plot(x,y2,color = 'blue',linewidth = 5.0, linestyle = '-')
plt.xticks(new_ticks)
plt.yticks([-1,0,1,2,3],
['level1','level2','level3','level4','level5'])
plt.show()