<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.youkuaiyun.com/qq_18246731/article/details/89380468">https://blog.youkuaiyun.com/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> </p>
使用可视化库matplotlib绘图时,plt.show()过后只出现<Figure size 640x480 with 1 Axes>
而没有生成图片
解决:
可以在前面添加
plt.figure()创建画布。
或者
导入库之后添加以下代码即可
%matplotlib inline
- 1
-
- import numpy as np
- from matplotlib import pyplot as plt
-
- x = np.arange(1,11)
- y = 2 * x + 5
- plt.title("Matplotlib demo")
- plt.xlabel("x axis caption")
- plt.ylabel("y axis caption")
- plt.plot(x,y)
- plt.show()
输出:<Figure size 640x480 with 1 Axes>
- 是在使用jupyter notebook 或者 jupyter qtconsole的时候,才会经常用到%matplotlib,也就是说那一份代码可能就是别人使用jupyter notebook 或者 jupyter qtconsole进行编辑的。
- 而%matplotlib具体作用是当你调用matplotlib.pyplot的绘图函数plot()进行绘图的时候,或者生成一个figure画布的时候,可以直接在你的python console里面生成图像。