zoukankan      html  css  js  c++  java
  • python学习笔记(一):作图

    1.需要导入的包

    import seaborn as sns
    import numpy as np
    from numpy.random import randn
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    from scipy import stats

    我用的是spyder,之前安装过numpy和scipy所以这次只用安装seaborn就可以了

    spyder环境下,可以用

    conda install seaborn 

    来安装seaborn

    如果遇到无法连接到下载网站的问题,可以通过添加清华镜像下载库(地址一定不能加引号!!)

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    
    conda config --set show_channel_urls yes

    如果不小心添加了错误的镜像,可以通过输入

    conda info -a

    来查看.condarc配置文件的地址,再打开这个配置文件把错误地址删掉就可以了

    2.画直方图

    plt.hist(data)
    plt.hist(data, bins=12, color=sns.desaturate("indianred", .8), alpha=.4)
    n, bins, patches = plt.hist(arr, bins=10, normed=0, facecolor='black', edgecolor='black',alpha=1,histtype='bar')

    hist的参数非常多,但常用的就这六个,只有第一个是必须的,后面四个可选

    arr: 需要计算直方图的一维数组

    bins: 直方图的柱数,可选项,默认为10

    normed: 是否将得到的直方图向量归一化。默认为0

    facecolor: 直方图颜色

    edgecolor: 直方图边框颜色

    alpha: 透明度

    histtype: 直方图类型,‘bar’, ‘barstacked’, ‘step’, ‘stepfilled’

    返回值 :

    n: 直方图向量,是否归一化由参数normed设定

    bins: 返回各个bin的区间范围

    patches: 返回每个bin里面包含的数据,是一个list

  • 相关阅读:
    02 _ 该如何选择消息队列
    封装、抽象、继承、多态分别可以解决哪些编程问题?
    04 _ 理论一:当谈论面向对象的时候,我们到底在谈论什么?
    03 _ 面向对象、设计原则、设计模式、编程规范、重构,这五者有何关系?
    接口使用
    结构体和方法
    通道的高级玩法
    通道的基本操作
    极客时间 mp3提取
    iOS多线程中的单例
  • 原文地址:https://www.cnblogs.com/pursuit1996/p/6050810.html
Copyright © 2011-2022 走看看