import matplotlib.pyplot as plt import numpy as np
x = np.linspace(-3, 3, 50) y1 = 2*x + 1 y2 = x**2
plt.figure() plt.plot(x, y2) # plot the second curve in this figure with certain parameters plt.plot(x, y1, color='red', linewidth=1.0, linestyle='--')
# 设置坐标轴范围 plt.xlim((-1, 2)) plt.ylim((-2, 3))
# 设置坐标轴名称 plt.xlabel('I am x') plt.ylabel('I am y')
# 设置坐标轴间隔 new_ticks = np.linspace(-1, 2, 5) plt.xticks(new_ticks) # use '$ $' for math text and nice looking, e.g. '$\pi$' plt.yticks([-2, -1.8, -1, 1.22, 3], [r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])