导入matplotlib和matplotlib.pyplot有什么区别? [英] What is the difference between importing matplotlib and matplotlib.pyplot?

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

问题描述

我对python还是很陌生,想知道x.y语句是否意味着y是x的子模块?如果是这样,则不执行以下命令:

I'm still fairly new to python and am wondering if the x.y statement means y is a submodule of x? And if so, doesn't the command:

import matplotlib.pyplot as plt

只导入这个特定的子模块而不导入其他任何东西?我必须这样做才能访问 hist 函数.这对调用 import matplotlib as plt 时通常导入的模块有何影响?我可以使用plt名称将matplotlib中的所有模块放在一起吗?

only import this particular submodule and nothing else? I had to do this in order to get access to the hist function. How does that affect the modules normally imported when calling import matplotlib as plt? Can I get all the modules in matplotlib together under the plt name?

我知道这个问题与

I'm aware that this question is related to what is the difference between importing python sub-modules from NumPy, matplotlib packages But the answer in this question does not tell me if nothing else in matplotlib is imported and how to just import all of matplotlib without worrying about submodules being left out.

推荐答案

我不知道从每个子模块导入所有功能的任何方法.您建议的方式可以从子模块导入所有功能,例如从 matplotlib.pyplot 导入 *.

I don't know of any way to import all the functions from every submodule. Importing all the functions from a submodule is possible the way you suggested with e.g. from matplotlib.pyplot import *.

要注意导入每个函数的潜在问题;您可以通过定义自己的同名函数来覆盖导入的函数.例如:

Be noted of a potential problem with importing every function; you may override imported functions by defining your own functions with the same name. E.g:

from matplotlib.pyplot import *

def plot():
    print "Hello!"

plot()

会输出

Hello!

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

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