代码如下
mpl.rcParams["font.sans-serif"] = ["SimHei"]
plt.title('profits')
plt.xlabel('迭代次数')
plt.ylabel('利润')
plt.xlim(0, len(Best_prof))
plt.ylim(100, 200)
plt.plot(range(1, len(Best_prof) + 1), Best_prof, c='red')
plt.plot(range(1, len(Best_prof) + 1), C_prof, c='blue')
x_major_locator = MultipleLocator(100)
y_major_locator = MultipleLocator(10)
ax = plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.legend(['最高利润', '当前利益'])
plt.show()
画多张图且在不同窗口
import matplotlib.pyplot as plt
plt.figure(1)
plt.plot()
plt.figure(2)
plt.plot()
画一张图包含多个子图
import matplotlib.pyplot as plt
plt.figure(1)
plt.subplot(1, 2, 1)
plt.plot()
plt.figure(1)
plt.subplot(1, 2, 2)
plt.plot()