DonJayamanne / vscodeJupyter

Jupyter for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=donjayamanne.jupyter
MIT License
335 stars 34 forks source link

BUG: Results window output overwritten when matplotlib is involved #82

Open dsanalytics opened 7 years ago

dsanalytics commented 7 years ago

Python v3.6.2 matplotlib v2.1.0 Visual Studio Code v1.17.0 OS 1: Windows 7 SP1 64bit Home Premium OS 2: Windows 10 64bit Home Premium Jupyter Notebook Server v5.0.0

This annoying little bug essentially prevents me from using VSCode for my work and I have to stick with FF+Jupyter-Notebook, thus would appreciate if this could be fixed at your earliest convenience.

The issue: Results windows content gets overwritten when cell's code is executed (single-run-single-cell) if matplotlib is involved. E.g. If I print something in code and show a chart in the line that follows within the same cell, printed text will be overwritten by chart. If the chart is shown first followed by the print line in the same cell, then the chart is overwritten by text. Attached 2 screenshots showing that issue + 1 screenshot showing jupyter notebook in FF with both chart and text shown properly. I don't want to use Append Results option as a workaround, because I do want results to be cleared between subsequent cell code runs. There are no errors, no crashes, and nothing reported in the Output window.

Steps to recreate: open VSCode, create new python file, paste the code below, and execute it with Ctrl+Enter. If the text and chart are shown properly (which actually happens on the 1st run), just execute the same code again with Ctrl+Enter and the issue should show itself.

Thank you in advance for your help.

The code:

%%

%matplotlib inline import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 20, 100) plt.plot(x, np.sin(x)) print('mean:',x.mean()) print('std dev:',x.std()) plt.show()

jupyter-notebook-in-a-browser vsc-jupyter-issue-image-1a vsc-jupyter-issue-image-1b

DonJayamanne commented 7 years ago

Please tick the check box 'Append Results'

dsanalytics commented 7 years ago

It appears that you did not read my post completely - I addressed Append Results option in the description - that option is not for that purpose, but for clearing/leaving outputs between subsequent executions of the same or a different cell code. This bug affects single run of the code within a single cell - it essentially displays only what's been printed/shown last.

Attached is a another screenshot of what happens when the code is run for the first time - as you can see, this time your code leaves all outputs and does not overwrite anything. Now run it again, and output will be different - see image no 2 below.

Please reopen the issue as it is valid report. Thank you.

vsc-jupyter-issue-image-1c

vsc-jupyter-issue-image-1a

DonJayamanne commented 7 years ago

Apologies for closing it prematurely.

dsanalytics commented 7 years ago

Not a problem at all - let me know if you need any extra info.

P.S. Thanks for your work on this great extension!

dsanalytics commented 7 years ago

Any updates on this? As I mentioned, this annoying bug makes VSC with matplotlib close to unusable.

P.S. Can anyone comment on their experience using Atom with python (sklearn, scipy, matplotlib, etc) for data science work and compare it to VSC experience? The main reason I wanted to use VSC rather than Jupyter Notebook is the right side panel that shows the results, instead of having to run-scroll-down-go-back-and-repeat. There are other reasons like security, etc.

DonJayamanne commented 7 years ago

@dsanalytics apologies for the delay in getting back to you on this. I'll look into this some time during the weekend. Please ping if you don't hear from me. Been quite busy making a lot of changes to another extension, that' taking a majority of my time.

dsanalytics commented 7 years ago

Thanks for getting back. In case those other extension changes are not critical (no showstoppers, no nasty crashes, etc), I'd appreciate if you could put this issue on top of your list. It seems to me as something simple to fix - as in omitted to set some flag, or forgot to check for matplotlib output type, etc. - things of that nature.

DonJayamanne commented 7 years ago

Yup, just look into this. Unfortunately I have not accounted for messages this simple scenario. I'm not passing any correlation id to the client side (responsible for clearing out the buffer).

dsanalytics commented 7 years ago

An ETA for this fix would be appreciated - thanks.

dsanalytics commented 6 years ago

Related: https://github.com/DonJayamanne/vscodeJupyter/issues/88

P.S. Congrats on your new employment with MS Don!

DonJayamanne commented 6 years ago

Thanks

anongit commented 6 years ago

Aa a workaround it's possible to click the button programmatically:

from IPython.display import Javascript, display

clear_results_js = Javascript('''
    [...document.querySelectorAll('button')]
        .filter(x => x.innerHTML == 'Clear Results')
        .forEach(x => x.click());
''')

clear_results = lambda: display(clear_results_js)
dsanalytics commented 6 years ago

@anongit - your workaround belongs to #105 and not here.

anongit commented 6 years ago

@dsanalytics I posted it here because I had the same use case, I wanted to clear output between subsequent cell code runs, but keep all output from the current run. I put clear_results at the beginning of a cell and run the cell with the "Append Results" option on.