zoukankan      html  css  js  c++  java
  • matplotlib浅析

      首先放出matplotlib的中英文文档:

      中文:https://www.matplotlib.org.cn/

      英文:https://matplotlib.org/3.1.1/index.html

      Matplotlib是一个Python 2D绘图库,可以生成各种硬拷贝格式和跨平台交互式环境的出版物质量数据。Matplotlib可用于Python脚本,Python和IPython shell,Jupyter笔记本,Web应用程序服务器和四个图形用户界面工具包(应当是指Tkinter,wxPython,Jython,PyQt。有时间可以学习一下,能够用这些工具包写出GUI)。

      1.安装:使用pip安装matplotlib即可

      2.使用:  

    import matplotlib.pyplot as plt
    import numpy as np  # numpy常和matplotlib搭配使用

        

      上图是一个Figure(可以)具有的全部元素。

      需要明白的一点是:Matplotlib是整个包,matplotlib.pyplot是matplotlib中的一个模块,pylab是一个与matplotlib一起安装的模块。

      我们使用的时候一般调用matplotlib.pyplot。下面举两个例子:

    x = np.linspace(0, 2, 100)
    
    plt.plot(x, x, label='linear')
    plt.plot(x, x**2, label='quadratic')
    plt.plot(x, x**3, label='cubic')
    
    plt.xlabel('x label')
    plt.ylabel('y label')
    
    plt.title("Simple Plot")
    
    plt.legend()
    
    plt.show()

      产生图形如下

       可见当三个plot画在同一张图上时,matplotlib会自动调整线条颜色,并且由plt.legend()控制是否有图例,plt.show()控制显示图像。

    x = np.arange(0, 10, 0.2)
    y = np.sin(x)
    fig, ax = plt.subplots()
    ax.plot(x, y)
    plt.show()

      产生图像如下:

  • 相关阅读:
    asp.net web api KnownTypeAttribute
    nodejs 递归创建目录
    nodejs 复制、移动文件
    windows cmd命令行下创建文件和文件夹
    nodejs http静态服务器
    C# Socket TCP Server & Client & nodejs client
    gem 安装nokigiri
    nsis 固定到任务栏
    SpringBoot整合JPA
    Freemaker FTL指令常用标签及语法
  • 原文地址:https://www.cnblogs.com/chester-cs/p/11623744.html
Copyright © 2011-2022 走看看