使用 Python 的 matplotlib 绘图库进行绘图

       matplotlib 是 Python 最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图。而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中。

  •  1  使用 Matplotlib.pyplot 快速绘图

         matplotlib通过pyplot模块提供了一套和MATLAB类似的绘图API,将众多绘图对象所构成的复杂结构隐藏在这套API内部。我们只需要调用pyplot模块所提供的函数就可以实现快速绘图以及设置图表的各种细节。pyplot模块虽然用法简单,但不适合在较大的应用程序中使用。

 1 import matplotlib.pyplot as plt
 2 
 3 plt.plot(df.iloc[:,0],df.iloc[:,1],'r*')
 4 x = df.iloc[solution_best,0]
 5 y = df.iloc[solution_best,1]
 6 plt.plot(x,y)
 7 plt.plot(df.iloc[[solution_best[CITY_NUM-1],solution_best[0]],0],df.iloc[[solution_best[CITY_NUM-1],solution_best[0]],1])
 8 
 9 plt.xlabel('x')
10 plt.ylabel('y ')
11 plt.title('Travelling Salesman Problem')
12 plt.legend()
13 plt.show()
14 
15 plt.plot(np.array(result))
16 plt.ylabel("The shortest distance")
17 plt.xlabel("t")
18 plt.legend()
19 plt.show()
20 
21 plt.plot(np.array(temp))
22 plt.ylabel("The shortest distance")
23 plt.xlabel("t")
24 plt.legend()
25 plt.show()

ref :

Python图表绘制:matplotlib绘图库入门

原文地址:https://www.cnblogs.com/shenxiaolin/p/7787814.html