使用可视化库matplotlib绘图时,plt.show()过后只出现Figure size 640x480 with 1 Axes而没有生成图片

                                            <div class="article-copyright">
            <span class="creativecommons">
            <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">
                </a>
        <span>
            版权声明:本文为博主原创文章,遵循<a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="noopener"> CC 4.0 BY-SA </a>版权协议,转载请附上原文出处链接和本声明。            </span>
           <div class="article-source-link2222">
                本文链接:<a href="https://blog.csdn.net/qq_18246731/article/details/89380468">https://blog.csdn.net/qq_18246731/article/details/89380468</a>
            </div>
        </span>
                </div>
                                                <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-3019150162.css">
                                    <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-3019150162.css">
            <div class="htmledit_views" id="content_views">
                                        <p>&nbsp;</p>

使用可视化库matplotlib绘图时,plt.show()过后只出现<Figure size 640x480 with 1 Axes>而没有生成图片

 

解决:

可以在前面添加

plt.figure()创建画布。

或者

导入库之后添加以下代码即可

%matplotlib inline

 
 
  • 1

 
 
  1. import numpy as np
  2. from matplotlib import pyplot as plt
  3. x = np.arange( 1, 11)
  4. y = 2 * x + 5
  5. plt.title( "Matplotlib demo")
  6. plt.xlabel( "x axis caption")
  7. plt.ylabel( "y axis caption")
  8. plt.plot(x,y)
  9. plt.show()
输出:<Figure size 640x480 with 1 Axes>
  • 是在使用jupyter notebook 或者 jupyter qtconsole的时候,才会经常用到%matplotlib,也就是说那一份代码可能就是别人使用jupyter notebook 或者 jupyter qtconsole进行编辑的。
  • 而%matplotlib具体作用是当你调用matplotlib.pyplot的绘图函数plot()进行绘图的时候,或者生成一个figure画布的时候,可以直接在你的python console里面生成图像。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值