我们在学习人工智能的时候,会经常用到matplotlib,在学习的时候有一些例子写了代码运行:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(20)
y = [x_i + np.random.rand(1) for x_i in x]
a, b = np.polyfit(x, y, 1)
plt.plot(x, y, 'o', np.arange(20), a*np.arange(20)+b, '-');

点击运行后却无反应

Process finished with exit code 0

其实很简单,只需要加上plt.show()即可。

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(20)
y = [x_i + np.random.rand(1) for x_i in x]
a, b = np.polyfit(x, y, 1)
plt.plot(x, y, 'o', np.arange(20), a*np.arange(20)+b, '-');
plt.show()

解决matplotlib库在PyCharm和命令行都无法正常显示问题

相关文章:

  • 2021-12-31
  • 2021-04-23
  • 2021-05-08
  • 2021-09-13
  • 2021-10-25
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-09-30
  • 2021-05-21
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2021-11-17
  • 2021-10-16
相关资源
相似解决方案