zoukankan      html  css  js  c++  java
  • 使用 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绘图库入门

  • 相关阅读:
    【docker】命令学习
    docker 安装mysql
    Docker DockerFile案例 自定义的tomcat9
    尚硅谷 Docker DockerFile案例 ONBUILD命令案例
    dockerfile 案例2 CMD ENTRYPOINT命令案例
    Dockerfile案例
    Dockerfile解析
    数据卷容器
    Dockfile添加数据卷
    容器数据卷
  • 原文地址:https://www.cnblogs.com/shenxiaolin/p/7787814.html
Copyright © 2011-2022 走看看