python - 是 "from matplotlib import pyplot as plt"== "import matplotlib.pyplot as plt"吗?

标签 python matplotlib python-import

from matplotlib import pyplot as plt

import matplotlib.pyplot as plt 

以上说法是否等价?哪种形式更具可读性/更好?

最佳答案

尽管它们是等价的,但我认为有一个很好的论据表明第二种形式 import matplotlib.pyplot as plt 客观上更具可读性:

  1. 通常习惯使用 import matplotlib.pyplot as plt 并在 matplotlib 文档中建议(参见 http://matplotlib.org/users/pyplot_tutorial.html 等...),因此大多数读者会更熟悉.

  2. import matplotlib.pyplot as plt 更短但同样清晰。

  3. import matplotlib.pyplot as plt 给不熟悉的读者一个提示 pyplot是一个模块,而不是可以从第一种形式错误假设的函数。

关于python - 是 "from matplotlib import pyplot as plt"== "import matplotlib.pyplot as plt"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30558087/

相关文章:

python - 运行 Django 开发服务器时出现 UnicodeDecodeError

python - 为 matplotlib 中的所有子图设置相同的轴限制

python - Mayavi - 在线框中隐藏 "diagonal"行

python - 导入非打包模块的python类

python - 使用 PyYAML 与 Python 的 YAML

python - Pandas `read_csv` 方法使用过多 RAM

python - 带范围的 pyobjc 索引访问器方法

python - 在函数中使用颜色条

Python 相对/绝对导入(再次)

python - Virtualenv 中的导入错误