zoukankan      html  css  js  c++  java
  • python之matplotlib1

    首先导入模板matplotlib并指名为plt,以免反复输入pyplot,pyplot包含了很多生成图表的函数,我们创造一和列表,里边保存了前述平方数,再把这个列表传递给plot(),使用plt.show()打开matplotlib的查看器,从而可以显示我们的绘图:

    import matplotlib.pyplot as plt
    squares = [1,4,9,16,25]
    plt.plot(squares)
    plt.show()

    我们可以调整图像上的标签字体大小和线条粗铣 

    import matplotlib.pyplot as plt
    squares = [1,4,9,16,25]
    
    plt.plot(squares,linewidth = 5)#设置线条粗细是5
    plt.title("Squares Values",fontsize = 24)#设置图标标题
    plt.xlabel('Value',fontsize = 15)#设置x轴信息提示,字体为15大小
    plt.ylabel('Squares',fontsize = 15)#设置y轴信息提示,字体为15大小
    plt.tick_params(axis='both',labelsize = 14)#设置刻度的样式,第一个参数会影响x和y轴的刻度
    
    plt.show()

    有时候编译器会给出初始假设值=0,使得我们的绘图从0开始,使得4的平方等于25这种错误现象,我们可以这么做

    import matplotlib.pyplot as plt
    input_value = [1,2,3,4,5]
    squares = [1,4,9,16,25]
    plt.plot(input_value,squares,linewidth = 4)
    plt.title("square values",fontsize = 14)
    plt.xlabel('values',fontsize = 10)
    plt.ylabel('squares',fontsize = 10)
    plt.tick_params(axis='both',labelsize = 14)
    
    plt.show()

    我们可以绘制一个离散的点,其中向scatter(x,y,s = 200)传递两个参数,x表示x坐标,y表示y坐标,s=给出这个点的大小尺寸

    import matplotlib.pyplot as plt
    plt.scatter(2,4,s = 200)
    
    #设置标题,xy轴的标签显示
    plt.title('point',fontsize = 14)
    plt.xlabel('x',fontsize = 10)
    plt.ylabel('y',fontsize = 10)
    plt.tick_params(axis='both',labelsize = 14)
    
    plt.show()
  • 相关阅读:
    kibana简单使用
    全文检索 高亮显示 数据库同步添加
    算法: Reverse Bits 反转位收藏
    算法:Number of 1 Bits 收藏
    JS创建二维数组
    查询状态在1,2,5,7的记录-oracle
    oracle 修改某字段,判断是否为空,如果为空赋默认值
    在运筹学中什么样的解决方案是最优的
    项目开发失败
    筛选符合条件的数据后,如何做数据源,绑定repeater
  • 原文地址:https://www.cnblogs.com/boost/p/13417904.html
Copyright © 2011-2022 走看看