美文网首页python爬虫人工智能学习笔记
解决matplotlib库在PyCharm和命令行都无法正常显示

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

作者: ImWiki | 来源:发表于2018-05-12 13:56 被阅读11次

    我们在学习人工智能的时候,会经常用到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()
    
    image.png

    相关文章

      网友评论

        本文标题:解决matplotlib库在PyCharm和命令行都无法正常显示

        本文链接:https://www.haomeiwen.com/subject/xpacdftx.html