最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - VSCode ipynb notebook showing the plots several times over - Stack Overflow

programmeradmin0浏览0评论

Does anyone know why my code does this in VSCode ? If I was using the jupyter notebook on a local host, I'm pretty sure it would not happen. Does anyone know how to fix that ?

if i write only ret_test.plot(), nothing shows up. I then write plt.show() and two to 5 plots show up. If I only write plt.show(), nothing happens.

Does anyone know why my code does this in VSCode ? If I was using the jupyter notebook on a local host, I'm pretty sure it would not happen. Does anyone know how to fix that ?

if i write only ret_test.plot(), nothing shows up. I then write plt.show() and two to 5 plots show up. If I only write plt.show(), nothing happens.

Share Improve this question edited Mar 3 at 23:00 President James K. Polk 42.1k30 gold badges109 silver badges145 bronze badges asked Mar 3 at 14:16 Willytom RigaudWillytom Rigaud 31 silver badge2 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

In VSCode's Jupyter implementation, plots can sometimes stack up and display multiple times. This is because each cell execution might be creating a new figure without clearing the previous ones

You can close all figures before plotting

plt.close('all')  # close all figures
ret_test.plot()
plt.show()

Also it is recommended to use %matplotlib inline at the beginning of your notebook. This ensures plots display properly without needing multiple plt.show() calls.

If you explicitly call plt.show() and the plot object is also the last line in the cell, Jupyter would display the plot twice. To suppress this behavior of displaying automatic output, simply add ; at the end of the last line.

发布评论

评论列表(0)

  1. 暂无评论