matplot模块中pyplot和pylab的区别

pylab的目的

Pylab combines the functionality of pyplot with the capabilities of NumPy in a single namespace, and therefore you do not need to import NumPy separately. Furthermore, if you import pylab, pyplot, and NumPy functions can be called directly without any reference to a module (namespace), making the environment more similar to Matlab.

简而言之,from pylab import *这一句话就引入了numpy、matplotlib等常用库,避免了多个import语句。一句话就创造了一个非常类似matlab的编程环境。

pylab的模块包括了许多NumPy和pyplot模块中常用的函数,方便用户快速进行计算和绘图,十分适合在IPython交互式环境中使用。

pylab模块非常单薄,查看pylab源代码可以发现此文件只有80余行,主要内容就是导入一堆包。matplot的主要内容还是在pyplot包中。

阅读以下程序,搜索一下引入的各个包的作用。

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

from matplotlib.externals import six

import sys, warnings

from matplotlib.cbook import flatten, is_string_like, exception_to_str, \
     silent_list, iterable, dedent

import matplotlib as mpl
# make mpl.finance module available for backwards compatability, in case folks
# using pylab interface depended on not having to import it
import matplotlib.finance

from matplotlib.dates import date2num, num2date,\
        datestr2num, strpdate2num, drange,\
        epoch2num, num2epoch, mx2num,\
        DateFormatter, IndexDateFormatter, DateLocator,\
        RRuleLocator, YearLocator, MonthLocator, WeekdayLocator,\
        DayLocator, HourLocator, MinuteLocator, SecondLocator,\
        rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, MONTHLY,\
        WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY, relativedelta

import matplotlib.dates  # Do we need this at all?

# bring all the  symbols in so folks can import them from
# pylab in one fell swoop

## We are still importing too many things from mlab; more cleanup is needed.

from matplotlib.mlab import griddata, stineman_interp, slopes, \
    inside_poly, poly_below, poly_between, \
    is_closed_polygon, path_length, distances_along_curve, vector_lengths

from matplotlib.mlab import window_hanning, window_none,  detrend, demean, \
     detrend_mean, detrend_none, detrend_linear, entropy, normpdf, \
     find, longest_contiguous_ones, longest_ones, \
     prctile, prctile_rank, \
     center_matrix, rk4, bivariate_normal, get_xyz_where, \
     get_sparse_matrix, dist, \
     dist_point_to_segment, segments_intersect, fftsurr, movavg, \
     exp_safe, \
     amap, rms_flat, l1norm, l2norm, norm_flat, frange,  identity, \
     base_repr, binary_repr, log2, ispower2, \
     rec_append_fields, rec_drop_fields, rec_join, csv2rec, rec2csv, isvector

import matplotlib.mlab as mlab
import matplotlib.cbook as cbook

from numpy import *
from numpy.fft import *
from numpy.random import *
from numpy.linalg import *

from matplotlib.pyplot import *

# provide the recommended module abbrevs in the pylab namespace
import matplotlib.pyplot as plt
import numpy as np
import numpy.ma as ma

# don't let numpy's datetime hide stdlib
import datetime

# This is needed, or bytes will be numpy.random.bytes from
# "from numpy.random import *" above
bytes = __builtins__['bytes']

注释之中列出了可用的命令:

This is a procedural interface to the matplotlib object-oriented
plotting library.

The following plotting commands are provided; the majority have
MATLAB |reg| [*]_ analogs and similar arguments.

.. |reg| unicode:: 0xAE

_Plotting commands
  acorr     - plot the autocorrelation function
  annotate  - annotate something in the figure
  arrow     - add an arrow to the axes
  axes      - Create a new axes
  axhline   - draw a horizontal line across axes
  axvline   - draw a vertical line across axes
  axhspan   - draw a horizontal bar across axes
  axvspan   - draw a vertical bar across axes
  axis      - Set or return the current axis limits
  autoscale - turn axis autoscaling on or off, and apply it
  bar       - make a bar chart
  barh      - a horizontal bar chart
  broken_barh - a set of horizontal bars with gaps
  box       - set the axes frame on/off state
  boxplot   - make a box and whisker plot
  violinplot - make a violin plot
  cla       - clear current axes
  clabel    - label a contour plot
  clf       - clear a figure window
  clim      - adjust the color limits of the current image
  close     - close a figure window
  colorbar  - add a colorbar to the current figure
  cohere    - make a plot of coherence
  contour   - make a contour plot
  contourf  - make a filled contour plot
  csd       - make a plot of cross spectral density
  delaxes   - delete an axes from the current figure
  draw      - Force a redraw of the current figure
  errorbar  - make an errorbar graph
  figlegend - make legend on the figure rather than the axes
  figimage  - make a figure image
  figtext   - add text in figure coords
  figure   - create or change active figure
  fill     - make filled polygons
  findobj  - recursively find all objects matching some criteria
  gca      - return the current axes
  gcf      - return the current figure
  gci      - get the current image, or None
  getp      - get a graphics property
  grid     - set whether gridding is on
  hist     - make a histogram
  hold     - set the axes hold state
  ioff     - turn interaction mode off
  ion      - turn interaction mode on
  isinteractive - return True if interaction mode is on
  imread   - load image file into array
  imsave   - save array as an image file
  imshow   - plot image data
  ishold   - return the hold state of the current axes
  legend   - make an axes legend
  locator_params - adjust parameters used in locating axis ticks
  loglog   - a log log plot
  matshow  - display a matrix in a new figure preserving aspect
  margins  - set margins used in autoscaling
  pause    - pause for a specified interval
  pcolor   - make a pseudocolor plot
  pcolormesh - make a pseudocolor plot using a quadrilateral mesh
  pie      - make a pie chart
  plot     - make a line plot
  plot_date - plot dates
  plotfile  - plot column data from an ASCII tab/space/comma delimited file
  pie      - pie charts
  polar    - make a polar plot on a PolarAxes
  psd      - make a plot of power spectral density
  quiver   - make a direction field (arrows) plot
  rc       - control the default params
  rgrids   - customize the radial grids and labels for polar
  savefig  - save the current figure
  scatter  - make a scatter plot
  setp      - set a graphics property
  semilogx - log x axis
  semilogy - log y axis
  show     - show the figures
  specgram - a spectrogram plot
  spy      - plot sparsity pattern using markers or image
  stem     - make a stem plot
  subplot  - make one subplot (numrows, numcols, axesnum)
  subplots - make a figure with a set of (numrows, numcols) subplots
  subplots_adjust - change the params controlling the subplot positions of current figure
  subplot_tool - launch the subplot configuration tool
  suptitle   - add a figure title
  table    - add a table to the plot
  text     - add some text at location x,y to the current axes
  thetagrids - customize the radial theta grids and labels for polar
  tick_params - control the appearance of ticks and tick labels
  ticklabel_format - control the format of tick labels
  title    - add a title to the current axes
  tricontour - make a contour plot on a triangular grid
  tricontourf - make a filled contour plot on a triangular grid
  tripcolor - make a pseudocolor plot on a triangular grid
  triplot - plot a triangular grid
  xcorr   - plot the autocorrelation function of x and y
  xlim     - set/get the xlimits
  ylim     - set/get the ylimits
  xticks   - set/get the xticks
  yticks   - set/get the yticks
  xlabel   - add an xlabel to the current axes
  ylabel   - add a ylabel to the current axes

  autumn - set the default colormap to autumn
  bone   - set the default colormap to bone
  cool   - set the default colormap to cool
  copper - set the default colormap to copper
  flag   - set the default colormap to flag
  gray   - set the default colormap to gray
  hot    - set the default colormap to hot
  hsv    - set the default colormap to hsv
  jet    - set the default colormap to jet
  pink   - set the default colormap to pink
  prism  - set the default colormap to prism
  spring - set the default colormap to spring
  summer - set the default colormap to summer
  winter - set the default colormap to winter
  spectral - set the default colormap to spectral

_Event handling

  connect - register an event handler
  disconnect - remove a connected event handler

_Matrix commands

  cumprod   - the cumulative product along a dimension
  cumsum    - the cumulative sum along a dimension
  detrend   - remove the mean or besdt fit line from an array
  diag      - the k-th diagonal of matrix
  diff      - the n-th differnce of an array
  eig       - the eigenvalues and eigen vectors of v
  eye       - a matrix where the k-th diagonal is ones, else zero
  find      - return the indices where a condition is nonzero
  fliplr    - flip the rows of a matrix up/down
  flipud    - flip the columns of a matrix left/right
  linspace  - a linear spaced vector of N values from min to max inclusive
  logspace  - a log spaced vector of N values from min to max inclusive
  meshgrid  - repeat x and y to make regular matrices
  ones      - an array of ones
  rand      - an array from the uniform distribution [0,1]
  randn     - an array from the normal distribution
  rot90     - rotate matrix k*90 degress counterclockwise
  squeeze   - squeeze an array removing any dimensions of length 1
  tri       - a triangular matrix
  tril      - a lower triangular matrix
  triu      - an upper triangular matrix
  vander    - the Vandermonde matrix of vector x
  svd       - singular value decomposition
  zeros     - a matrix of zeros

_Probability

  normpdf   - The Gaussian probability density function
  rand      - random numbers from the uniform distribution
  randn     - random numbers from the normal distribution

_Statistics

  amax      - the maximum along dimension m
  amin      - the minimum along dimension m
  corrcoef  - correlation coefficient
  cov       - covariance matrix
  mean      - the mean along dimension m
  median    - the median along dimension m
  norm      - the norm of vector x
  prod      - the product along dimension m
  ptp       - the max-min along dimension m
  std       - the standard deviation along dimension m
  asum      - the sum along dimension m
  ksdensity - the kernel density estimate

_Time series analysis

  bartlett  - M-point Bartlett window
  blackman  - M-point Blackman window
  cohere    - the coherence using average periodiogram
  csd       - the cross spectral density using average periodiogram
  fft       - the fast Fourier transform of vector x
  hamming   - M-point Hamming window
  hanning   - M-point Hanning window
  hist      - compute the histogram of x
  kaiser    - M length Kaiser window
  psd       - the power spectral density using average periodiogram
  sinc      - the sinc function of array x

_Dates

  date2num  - convert python datetimes to numeric representation
  drange    - create an array of numbers for date plots
  num2date  - convert numeric type (float days since 0001) to datetime

_Other

  angle     - the angle of a complex array
  griddata  - interpolate irregularly distributed data to a regular grid
  load      - Deprecated--please use loadtxt.
  loadtxt   - load ASCII data into array.
  polyfit   - fit x, y to an n-th order polynomial
  polyval   - evaluate an n-th order polynomial
  roots     - the roots of the polynomial coefficients in p
  save      - Deprecated--please use savetxt.
  savetxt   - save an array to an ASCII file.
  trapz     - trapezoidal integration

__end

.. [*] MATLAB is a registered trademark of The MathWorks, Inc.
时间: 2024-10-15 02:34:27

matplot模块中pyplot和pylab的区别的相关文章

【MM ECC VS S4】MM模块中ECC与S4的区别

原文出自 https://blogs.sap.com/2017/04/28/comparison-of-simplification-and-functionality-in-s4-and-ecc-in-procurement-process/ Functionality/Element ECC S/4 Material Master Material Number length is 18 characters Service Master is used for Services. Mate

node.js模块中exports和module.exports的区别

Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个模块,有自己的作用域.在一个文件里面定义的变量.函数.类,都是私有的,对其他文件不可见. CommonJS规范规定,每个模块内部,module变量代表当前模块.这个变量是一个对象,它的exports属性(即module.exports)是对外的接口.加载某个模块,其实是加载该模块的module.exports属性. var x = 5; var addX = function (value) { return

VBA中Let与Set的区别

Let与Set的区别 1.在"类模块"中 Property Let 语句 在Class块中,是给普通变量进行赋值操作的Property,该种Property将不能在其前面使用Set,因而将不能用户对对象变量的赋值. Property Set 语句 在Class块中,是给对象变量进行设置引用操作的Property. Property Get 语句 在Class块中,取得(返回)的值的Property,返回值可以是对象变量或普通变量. 2.在"普通模块"中 Let语句是

模块与包 Mysql与Oracle区别

1 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编写的代码(.py文件) 2 已被编译为共享库或DLL的C或C++扩展 3 包好一组模块的包 4 使用C编写并链接到python解释器的内置模块 2),模块的执行:import,每个模块都是一个独立的名称空间. 模块可以包含可执行的语句和函数的定义,这些语句的目的是初始化模块,它们只在模块名第一次遇到导入imp

Python中浅拷贝和深拷贝的区别

Python中浅拷贝和深拷贝的区别 浅拷贝和深拷贝示意图 如上图,简单点说 1. copy.copy 浅拷贝 只拷贝父对象,不会拷贝对象的内部的子对象. 2. copy.deepcopy 深拷贝 拷贝对象及其子对象 数字,字符串是不可变类型 列表,字典是可变类型 我们看下面的案例 案例一:浅拷贝 >>> import copy     #导入copy模块                >>> s=['name',['savings',100.0]] #赋值给s >

在requests模块中使用代理发送请求

1. 代理概述 玩爬虫为什么我们不能使用一个固定IP发送请求 你使用一个固定IP发送每秒向对方服务器发送10几个请求,对方认为这样操作不是人干的, 就把你IP给封了 服务器端的人可以根据你IP很快锁定你, 要求你对这种窃取行为赔偿. 代理 正向代理与反向代理 正向代理与反向代理的区别 反向代理: 服务器端知道代理的存在,反向代理是为了保护服务器或负责负载均衡 但是客户端不知道代理的存在的 正向代理: 客户端知道代理的存在,正向代理是为保护客户端,防止追究责任. 但是服务端不知道真实的客户端 2.

re模块中常用功能函数

re模块中常用功能函数 正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配. Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式. re 模块使 Python 语言拥有全部的正则表达式功能. compile 函数根据一个模式字符串和可选的标志参数生成一个正则表达式对象.该对象拥有一系列方法用于正则表达式匹配和替换. re 模块也提供了与这些方法功能完全一致的函数,这些函数使用一个模式字符串做为它们的第一个参数. re.match函数

Vue中 export default 和 export 区别

1.export与export default均可用于导出常量.函数.文件.模块等2.在一个文件或模块中,export.import可以有多个,export default仅有一个3.通过export方式导出,在导入时要加{ },export default则不需要 4. (1) 输出单个值,使用export default (2) 输出多个值,使用export (3) export default与普通的export不要同时使用 示例: 1.export //a.js export const

光模块的单模和多模的区别

光模块(opTIcalmodule)由光电子器件.功能电路和光接口等组成,光电子器件包括发射和接收两部分.发射部分是:输入一定码率的电信号经内部的驱动芯片处理后驱动半导体激光器(LD)或发光二极管(LED)发射出相应速率的调制光信号,其内部带有光功率自动控制电路,使输出的光信号功率保持稳定.接收部分是:一定码率的光信号输入模块后由光探测二极管转换为电信号.经前置放大器后输出相应码率的电信号. 简单的说,光模块的作用就是光电转换,发送端把电信号转换成光信号,通过光纤传送后,接收端再把光信号转换成电