zoukankan      html  css  js  c++  java
  • (原)python中使用plt.show()时显示图像

    转载请注明出处:

    http://www.cnblogs.com/darkknightzh/p/6039667.html

    参考网址:

    http://matplotlib.org/users/shell.html

    使用python的matplotlib时,imshow后,提示:

    Backend TkAgg is interactive backend. Turning interactive mode on.

    能够保存图像,但是不能显示图像。

    实际上使用如下代码即可显示图像(加上第二句话):

    import matplotlib.pyplot as plt
    plt.ion()

    ===================================================

    161125更新

    今天使用的时候,又死活不能显示显示。

    后来在http://matplotlib.org/api/pyplot_api.html中,随便下了一个代码,跑了一下可以用,发现自己的代码由于使用了

    import matplotlib as mpl
    mpl.use('Agg')

    导致show时不显示图像。

    最终代码如下:

     1 import matplotlib as mpl
     2 #mpl.use('Agg')
     3 import matplotlib.pyplot as plt
     4 #plt.style.use('bmh')
     5 
     6 fig, ax = plt.subplots(1, 1)
     7 x = [1, 2, 3, 4, 5]
     8 y = [2, 4, 6, 8, 10]
     9 plt.plot(x, y)
    10 plt.show()

    当注释掉第2行后,就能显示图像;不注释,就不会显示图像(其实上面代码的第一行也没用,第4行也没用)。

    哎,以后贴代码还是要贴全。否则还是会忘了。。。

    161125更新结束

    ===================================================

  • 相关阅读:
    html5语法
    Addthis使用
    css font-weight原理
    css3 background
    jquery对标签属性操作
    给textarea添加背景图
    label的for属性
    css3 text-shadow
    z-index堆叠规则
    css3 @font-face
  • 原文地址:https://www.cnblogs.com/darkknightzh/p/6039667.html
Copyright © 2011-2022 走看看