zoukankan      html  css  js  c++  java
  • python--matplotlib库使用2

    功能:python画2D图

    直接上代码,注释很详细!

     1 #-*- coding:utf-8 -*-
     2 
     3 from numpy import *
     4 import matplotlib.pyplot as plt
     5 
     6 A=array([0,0]);B=array([[1,0],[0,1]])
     7 #生成以A为均值,以B为协方差矩阵,并满足正态分布的随机数
     8 C1=random.multivariate_normal(A,B,10)          #10*2
     9 C2=random.multivariate_normal(A+0.1,B+0.1,20)  #20*2
    10 C2=mat(C2)    #这样做只是为了说明ndarray和matrix型数据的不同
    11 
    12 fig=plt.figure(figsize=(5,5))  #制定画布大小
    13 ax=fig.add_subplot(111)
    14 
    15 #ndarray型数据C1,shpe(C1)得到(10L,);matrix型C=mat(C1),shpe(C[:,1])得到(10L,1L)
    16 ax.scatter(C1[:,0],C1[:,1],s=50,c='r',marker='o',alpha=0.5,label='C1')
    17 ax.scatter(C2[:,0].flatten().A[0],C2[:,1].flatten().A[0],s=30,c='b',marker='^',alpha=0.5,label='C2')
    18 '''
    19 scatter(x,y,x=None,c=None,marker=None)
    20 x,y必须是1-D
    21 marker为标记,s控制标记的大小,c控制标记的颜色
    22 flatten()函数 :a.flatten(),得到一个将a转换为1-D的copy
    23 另外,matrix(也就是mat(a))才有A属性,可以使用mat(a).flatten().A[0],得到一个1-D的“array”
    24 '''
    25 plt.title('scatter plot')
    26 plt.xlabel('the Variable X')
    27 plt.ylabel('the Variable Y')
    28 
    29 ax.legend(loc='upper left')      #确定方框位置
    30 plt.show()

    关于官方pyplot.scatter()函数详解见:http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.scatter

      

  • 相关阅读:
    程序保护机制
    ubuntu单独安装DDMS
    Linux Syste m Call Table
    任意程序添加ShellCode
    解析结构化异常处理(SEH)(第一部分)
    CONTEXT(线程结构体)
    WINNT.H
    Html的空格显示
    随机变量的联合分布
    期望和期望的性质
  • 原文地址:https://www.cnblogs.com/cygalaxy/p/6804306.html
Copyright © 2011-2022 走看看