22
numpy库
numpy库常用的创建数组函数
| 函数 | 描述 |
| np.array([x,y,z],dtype=int) |
从python列表和元组创造数组 |
| np.arange(x,y,i) | 创建一个由x到y,以i为步长的数组 |
| np.linspace(x,y,n) | 创建一个由x到y,等分成n个元素的数组 |
| np.indices((m,n)) | 创建一个m行n列的矩阵 |
| np.random.rand(m,n) | 创建一个m行n列的随机矩阵 |
| np.ons((m,n),dtype) | 创建一个m行n列全1的数组,dtype是数据类型 |
| np.empty((m,n),dtype) | 创建一个m行n列全0的数组,dtype是数据类型 |
numpy库ndarray类的常用属性
| 属性 | 描述 |
| ndarry.ndim | 数组轴的个数,也被称作轴 |
| ndarry.shape | 数组在每个维度上大小的整数元组 |
| ndarray.size | 数组元素的总个数 |
| ndarray.dtype | 数组元素的数据类型,dtype类型可以用于创建数组中 |
| ndarray.itemsize | 数组中每个元素的字节大小 |
| ndarry.data | 包含实际数组元素的缓冲区地址 |
| ndarry.flat | 数组元素的迭代器 |
numpy库ndarray类的形态操作方法
| 方法 | 描述 |
| ndarray.reshape(n,m) | 不改变数组ndarry,返回一个维度为(n,m)的数组 |
| ndarray.resize(new_shape) | 与reshape()作用相同,直接修改数组ndarray |
| ndarray.swapaxes(ax1,ax2) | 将数组n个维度中任意两个维度进行调换 |
| ndarray.flatten() | 对数组进行降维,返回一个折叠后的一维数组 |
| ndarray.ravel() | 作用同np.flatten(),但是返回数组的一个视图 |
numpy 库的算术运算函数
| 函数 | 描述 |
| np.add(x1,x2[,y]) | y = x1 + x2 |
| np.subtract(x1,x2[,y]) | y = x1 - x2 |
| np.multiply(x1,x2[,y]) | y = x1*x2 |
| np.divide(x1,x2[,y]) | y = x1/x2 |
| np.floor_divide(x1,x2[,y]) | y = x1//x2 |
| np.negative(x[,y]) | y = -x |
| np.power(x1,x2[,y]) | y = x1**x2 |
| np.remainder(x1,x2[,y]) | y = x1%x2 |
numpy库的比较运算函数
| 函数 | 符号描述 |
| np.equal(x1,x2[,y]) | y=x1==x2 |
| np.not_equal(x1,x2[,y]) | y=x1!=x2 |
| np.less(x1,x2[,y]) | y=x1<x2 |
| np.less_equal(x1,x2[,y]) | y=x1<=x2 |
| np.greater(x1,x2[,y]) | y=x1>x2 |
| np.greater_equal(x1,x2[,y]) | y=x1>=x2 |
| np.where(condition[x,y]) | 根据给出的条件判断输出x还是y |
matplotlib库
matplotlib.pyplot库
plt库的绘画区域函数
| 函数 | 描述 |
| plt.figure(figsize=None, facecolor=None) | 创建一个全局绘图区域 |
| plt.axes(rect,axisbg='w') | 创建一个坐标系风格的子绘画区域 |
| plt.subplot(nrows,ncols,plot_number) | 在全局绘图区域中创建一个子绘画区域 |
| plt.subplots_adjust() | 调整子图区域的布局 |
plt库的读取和显示函数
| 函数 | 描述 |
| plt.legend() | 在绘图区域中方式绘图标签(也称图注) |
| plt.show() | 显示创建的绘图对象 |
| plt.matshow() | 在窗口显示数组矩阵 |
| plt.imshow() | 在axes上显示图像 |
| plt.imsave() | 保存数组为图像文件 |
| plt.omread() | 从图像文件中读取数组 |
plt库的基础图标函数
| 操作 | 描述 |
| plt.polt(x,y,label,color,width) | 根据x,y数组绘制直/曲线 |
| plt.boxplot(data,notch,position) | 绘制一个箱型图(Box-plot) |
| plt.bar(left,height,width,bottom) | 绘制一个条形图 |
| plt.barh(bottom,width,height,left) | 绘制一个横向条形图 |
| plt.polar(theta.r) | 绘制极坐标图 |
| plt.pie(data.explode) | 绘制饼图 |
| plt.psd(x,NFFT=256.pad_t,Fs) | 绘制功率谱密度图 |
|
plt.specgram(x,NFFT=256.pad_t,F)
|
绘制谱图 |
| plt.cohere(x,y,NFFT=256,fs) | 绘制X-Y的相关性函数 |
| plt.scatter() | 绘制散点图(x,y是长度相同的序列) |
| plt.step(x,y,where) | 绘制步阶图 |
| plt.hist(x,bins,normed) | 绘制直方图 |
| plt.contour(X,Y,Z,N) | 绘制等值线 |
| plt.vlines() | 绘制垂直线 |
| plt.stem(x,y,linfmt,markerfmt,basefmt) | 绘制曲线每个点到水平轴线的垂线 |
| plt.plot_data() | 绘制数据日期 |
| plt.plotfile() | 绘制数据后写入文件 |
plt库的坐标轴设置函数
| 函数 | 描述 |
| plt.axis('v',off,'equal','tight','image') | 获取设置轴属性的快捷方法 |
| plt.xlim(xmin,xmax) | 设置当前x轴的取值范围 |
| plt.ylim(ymin,ymax) | 设置当前y轴取值范围 |
| plt.xscale() | 设置x轴的缩放 |
| plt.yscale() | 设置y轴的缩放 |
| plt.autoscale() | 自动缩放轴视图的数据 |
| plt.thetagrids(angles,labels,fmt,frac) | 设置极坐标theta的位置 |
| plt.grid(on/off) | 打开或者关闭坐标网络 |
plt库的标签设置函数
| 函数 | 描述 |
| plt.figlegend(handles,label,loc) | 为全局绘图区域放置图注 |
| plt.lengend() | 为当前坐标图放置图注 |
| plt.xlabel(s) | 设置当前x轴的标签 |
| plt.ylabel(s) | 设置当前y轴的标签 |
| plt.xticks(array,'a','b','c') | 设置当前x轴刻度位置的标签和值 |
| plt.yticks(array,'a','b','c') | 设置当前y轴刻度位置的标签和值 |
| plt.clabel(cs,v) | 为等值线图设置标签 |
| plt.get_figlabels() | 返回当前绘图区域的标签列表 |
| plt.figtext(x,y,s,fontdic) | 为全局绘图区域添加文字 |
| plt.title() | 设置标题 |
| plt.suptitle() | 为当前绘图区域添加中心标题 |
| plt.text(x,y,s,fontdic,withdash) | 为坐标图轴添加注释 |
| ply.annotate(note,xy,xytext,xycoords,textcoords,arrowprops) | 用箭头在指定数据点创建一个注释或一段文本 |
浙公网安备 33010602011771号