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()
  • 相关阅读:
    Spring MVC- 表单提交
    Ajax提交与传统表单提交的区别说明
    CSS各种居中方法
    Android RecyclerView 使用完全解析 体验艺术般的控件
    如何解决VMware上MAC虚拟机不能上网问题
    input标签的hidden属性的应用及作用
    SpringMVC表单标签简介
    EL显示List里嵌套map(Spring MVC3)返回的model
    Spring3 MVC请求参数获取的几种方法
    写数据到文件,并同步到磁盘
  • 原文地址:https://www.cnblogs.com/boost/p/13417904.html
Copyright © 2011-2022 走看看