zoukankan      html  css  js  c++  java
  • python绘图03

    左右子图

    有时候,选择两个不同的图标类型来可视化数据可能是必要的或者是理想的.利用子图方法:

    #!/etc/bin/python
    #coding=utf-8
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    np.random.seed(2000)
    y = np.random.standard_normal((10, 2))
    
    plt.figure(figsize=(10,5))
    plt.subplot(121)  #两行一列,第一个图
    plt.plot(y[:,0], lw = 1.5,label = '1st')
    plt.plot(y[:,0], 'ro')
    plt.grid(True)
    plt.legend(loc = 0) #图例位置自动
    plt.axis('tight')
    plt.xlabel('index')
    plt.ylabel('value')
    plt.title('1st Data Set')
    
    plt.subplot(122)
    plt.bar(np.arange(len(y)), y[:,1],width=0.5, color='g',label = '2nc')
    plt.grid(True)
    plt.legend(loc=0)
    plt.axis('tight')
    plt.xlabel('index')
    plt.title('2nd Data Set')
    plt.show()

    其他绘图样式,散点图,直方图等

    #!/etc/bin/python
    #coding=utf-8
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    np.random.seed(2000)
    y = np.random.standard_normal((1000, 2))
    plt.figure(figsize=(7,5))
    plt.scatter(y[:,0],y[:,1],marker='o')
    plt.grid(True)
    plt.xlabel('1st')
    plt.ylabel('2nd')
    plt.title('Scatter Plot')
    plt.show()

    2.直方图 plt.hist
    #!/etc/bin/python
    #coding=utf-8
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    np.random.seed(2000)
    y = np.random.standard_normal((1000, 2))
    plt.figure(figsize=(7,5))
    plt.hist(y,label=['1st','2nd'],bins=25)
    plt.grid(True)
    plt.xlabel('value')
    plt.ylabel('frequency')
    plt.title('Histogram')
    plt.show()

  • 相关阅读:
    [SCOI2016]幸运数字
    [CQOI2013]新Nim游戏
    POJ-2485 Highways---最小生成树中最大边
    最小生成树之kruskal算法
    POJ-1789 Truck History---最小生成树Prim算法
    最小生成树之prim算法
    POJ-1182 食物链---并查集(附模板)
    POJ-2993 Emag eht htiw Em Pleh---棋盘模拟
    POJ-2996 Help Me with the Game---模拟棋子
    POJ-1573 Robot Motion模拟
  • 原文地址:https://www.cnblogs.com/huaobin/p/15692174.html
Copyright © 2011-2022 走看看