“pylab"和“pylab"有什么区别?和"matplotlib.pyplot"? [英] What is a difference between "pylab" and "matplotlib.pyplot"?

查看:51
本文介绍了“pylab"和“pylab"有什么区别?和"matplotlib.pyplot"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用MatPlotLib,我意识到可以用两种不同的方式导入它,并且在两种情况下都可以工作(以相同的方式):将pylab导入为p import matplotlib.pyplot 作为 p.

I try to use MatPlotLib and I have realized that can import it in two different ways and in both cases it works (in the same way): import pylab as p or import matplotlib.pyplot as p.

那么,我的问题是这两种方式有什么区别?

So, my question is what is the difference between these two ways?

推荐答案

来自 Pylab 将 pyplot 功能(用于绘图)与 numpy功能(用于数学和使用数组)在一个单个名称空间,使该名称空间(或环境)更加丰富像MATLAB一样.例如,可以只调用sin和cos函数就像在 MATLAB 中一样,并且拥有pyplot.

Pylab combines the pyplot functionality (for plotting) with the numpy functionality (for mathematics and for working with arrays) in a single namespace, making that namespace (or environment) even more MATLAB-like. For example, one can call the sin and cos functions just like you could in MATLAB, as well as having all the features of pyplot.

请注意,pylab仅从顶部的numpy名称空间导入.因此,这会很重要

Note that pylab only imports from the top numpy namespace. Therefore, this will worK

import numpy
numpy.array # works
numpy.distutils # finds a module

这不会

import pylab
pylab.array # works, is actually numpy array
pylab.distutils # gives an error

这篇关于“pylab"和“pylab"有什么区别?和"matplotlib.pyplot"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆