【Python-BUG】module ‘matplotlib‘ has no attribute ‘plot‘

问题所在

import matplotlib.pyplot as plt
#很容易漏掉pyplot ,直接写成 import matplotlib as plt导致错误

错误写法

import numpy as np
import matplotlib as plt
# 随机漫步
position=0
walk=[position]
steps=1000
for i in range(steps):
    step= 1 if np.random.randint(0,2) else -1
    position+=step
    walk.append(position)
plt.plot(walk)

正确写法

import numpy as np
import matplotlib.pyplot as plt
# 随机漫步
position=0
walk=[position]
steps=1000
for i in range(steps):
    step= 1 if np.random.randint(0,2) else -1
    position+=step
    walk.append(position)
plt.plot(walk)
上一篇:Python模拟登录,matplotlib模块,Python模拟太阳-地球-月亮运动模型


下一篇:人工智能机器学习有关-Matplotlib工具的使用(二)