vscode-jupyter icon indicating copy to clipboard operation
vscode-jupyter copied to clipboard

Allow copying an image result from Python Interactive window

Open andrewdelong opened this issue 6 years ago • 31 comments

Environment data

  • VS Code version: 1.30.2
  • Extension version (available under the Extensions sidebar): 2018.12.1
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda Python 3.7.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: None

Expected behaviour

It'd be great if Python plots within the IDE could be copied to the clipboard. I'd expect right-click to show a menu with "Copy" as an option, for example.

Copying pasting quick plots into Slack/e-mail is super convenient for sharing intermediate results with colleagues.

Actual behaviour

Copying code from Python Interactive works (including rich formatting), but copying images does not. Right-clicking on the image does not show a menu. Selecting the image as part of the surrounding code does not include the image.

Workaround: Take screenshot, paste into image editor, crop, copy-paste the crop, close image editor.

Steps to reproduce:

  1. Paste this into a .py script
#%%
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x))
  1. Click "Run Cell" in the editor.
  2. Try to copy the resulting plot to the clipboard.

andrewdelong avatar Jan 24 '19 17:01 andrewdelong

Selecting and "ctrl-c" on the plot in the Interactive window will copy the image out. Though we don't yet have a context menu support for this.

IanMatthewHuff avatar Jan 24 '19 21:01 IanMatthewHuff

Thanks @IanMatthewHuff. I tried more ideas due to your comment, and you're right that I can paste into GSuite (Gmail, GDocs). It still doesn't work for Slack (Windows, Linux) or Word (Windows), but having it work for GSuite is already very helpful -- thanks!

Summary of current situation:

Copy action from IPython Interactive Gmail GDoc Slack Word
Drag image from one window to the other Works Works No No
Select image as part of text, then Ctrl+C Works Works No No
Right click on image, select "Copy" No No No No

andrewdelong avatar Jan 25 '19 15:01 andrewdelong

@andrewdelong Thanks for checking that out for us. Glad that you are (somewhat) unblocked for now. I'll look into the pasting issues as I'm surprised that Word in particular doesn't work. We also want to get a context menu in here for this so it's more discoverable.

IanMatthewHuff avatar Jan 25 '19 19:01 IanMatthewHuff

I was just playing with this a bit myself and I was able to paste into Word, but it was odd. Some sections would paste and others would not and getting selection correct was tricky as well. Will have to look into this more as a whole "copy / paste correctly" meta issue.

IanMatthewHuff avatar Jan 25 '19 19:01 IanMatthewHuff

https://stackoverflow.com/questions/54930530/how-to-save-images-from-python-interactive-tab-in-microsoft-visual-studio-code/54930957#54930957

SO issue. In addition to Copy have a save to file button?

IanMatthewHuff avatar Feb 28 '19 17:02 IanMatthewHuff

Somewhat related to this is the 'theme' for the plot. We force dark on dark themes, but the user may wish to save/copy the plot as a different theme. See some of the discussion in microsoft/vscode-python#4009

rchiodo avatar Mar 05 '19 17:03 rchiodo

@IanMatthewHuff is it possible that selection support for output images was removed in the last few versions? I've got extension version 2019.3.6558 and clicking on output images does nothing. Neither does pressing ctrl-c. :(

This is my first time trying VSCode for Jupyter notebooks and I immediately ran into this problem since my primary way of getting images out of notebooks and into emails / presentations is copy&pasting them.

Also I'll need to find a way to get rid of the dark theme on plots, but that's another google.

stmax82 avatar Apr 15 '19 12:04 stmax82

Hey @stmax82 . Currently the support that we do / did have for selecting output images is just based on what we get by default for being in a vscode hosted webview. I don't believe that it should have changed recently, but since this is not something that we have directly added we don't have any specific tests around it. We have the issue referenced above for getting this support fully in and solid.

For what it's worth I just poked around a bit myself. If I did a drag selection over the matplotlib graph (so that I could see a selection around it) I was able to ctrl-c it and paste it into word. Sorry that we don't have this better supported yet, but does that work for you as a workaround?

CopyImage

IanMatthewHuff avatar Apr 17 '19 20:04 IanMatthewHuff

@IanMatthewHuff looks like the trick is selecting the image by dragging the mouse over it - not clicking on it (like I tried before). But still, not sure what I'm doing wrong, this is what I get:

Selection in VS Code:

pic1

Result in Word:

pic2

Anyway, I can already move some notebooks over to VS Code where I don't need to export the plots and keep the rest in jupyter for a while.

stmax82 avatar Apr 25 '19 13:04 stmax82

Sorry I'm not able to repro that odd looking box in your copy result. I think that might be how the code input box that use at the bottom to enter new code is coming out in a copy operation. I think that the best thing we can say for now is that this issue is open and on our radar to make sure that we have a good copy story.

IanMatthewHuff avatar Apr 25 '19 22:04 IanMatthewHuff

Let's support a context menu on images with "Open Viewer" and "Copy".

greazer avatar Jun 06 '19 21:06 greazer

This isn't possible without this working: https://github.com/microsoft/vscode/issues/217

rchiodo avatar Jun 11 '19 17:06 rchiodo

Being able to alter the appearance of images (matplotlib themes) regardless of the VS Code theme would be useful. I also think being able to easily copy and/or export the images would be useful.

I see a button to "Export to different formats" but it doesn't do anything when I click on it.

image

dpsugasa avatar Sep 06 '19 14:09 dpsugasa

@dpsugasa the export button should allow you to save as PDF/PNG. That was working until this change: https://github.com/microsoft/vscode-python/pull/7181

Although unless you're on our insider's build, you shouldn't have that change. I've added an issue (https://github.com/microsoft/vscode-python/issues/7257) to fix that before our next release.

In relation to this request:

Being able to alter the appearance of images (matplotlib themes) regardless of the VS Code theme would be useful

I don't think that will be coming anytime soon. We don't do the plotting ourselves (it's handled by Jupyter) and in order to generate an image in a different theme, we'd have to rerun the plot code.

rchiodo avatar Sep 06 '19 15:09 rchiodo

It'll be cool if we can copy the image straight from vscode.

alext234 avatar Oct 17 '19 00:10 alext234

Not quite the same issue as above but related and I can't find a more similar issue. Is it possible to expand images from the python interactive window into the plots viewer programmatically (rather than having to click on the 'Expand image' button for individual images)?

michaelberks avatar Dec 06 '19 17:12 michaelberks

@michaelberks sorry but that is not possible. I assume you mean with code in your cell?

Could you enter a new issue for this suggestion? Thanks.

rchiodo avatar Dec 06 '19 17:12 rchiodo

I assume you mean with code in your cell?

Yes, exactly. I'll open a new issue, would be a hugely useful feature for me.

UPDATE: Just created as issue microsoft/vscode-python#8947, thanks!

michaelberks avatar Dec 06 '19 17:12 michaelberks

I also found I can drag and drop into google products (Gmail, Google Slides)

On Mac, a work around to get to Slack is drag and drop into Finder, a .png file is rendered, then drag and drop into Slack (or wherever)

rstoddard24 avatar Jan 15 '21 22:01 rstoddard24

It's 2021, it would be good to be able to copy the figures from the interactive figure viewer...

andreimargeloiu avatar Jan 18 '21 19:01 andreimargeloiu

Any development on this issue?

berkdemir avatar Feb 03 '21 15:02 berkdemir

Sorry but this is not currently supported. There is no context menu for output in either the stable or insiders build nor any way to use the clipboard to copy output images. This should probably be an upstream bug in VS code.

The only thing that works (on windows) is you can drag images out of the view to windows explorer to create a download.png.

rchiodo avatar Feb 03 '21 17:02 rchiodo

Moving back to triage to see if we can get VS code to support copy on output.

rchiodo avatar Feb 03 '21 17:02 rchiodo

Any option such as right click menu or button after double click (currently downloads as pdf) would be great. Spyder works great in this manner.

3 Şub 2021 Çar 20:19 tarihinde Rich Chiodo [email protected] şunu yazdı:

Moving back to triage to see if we can get VS code to support copy on output.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode-jupyter/issues/1470#issuecomment-772677475, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUM4XH4ACF4AJ2VJLFIC5LS5GAR3ANCNFSM4TVD4NBQ .

berkdemir avatar Feb 03 '21 17:02 berkdemir

Just wanna discuss with VS Code team about what could be done here.

greazer avatar Feb 04 '21 00:02 greazer

with today updating. Double click doesn't go edit panel.

linzhlalala avatar Jun 30 '21 00:06 linzhlalala

It is possible to save the file to local and then copy it. However copying it directly from the output would save us some time.

ceronvgabriel avatar Jul 23 '21 02:07 ceronvgabriel

It would be very useful to get this feature. I ended using the Snipping Tool as a workaround, which is almost as fast as being able to CTRL+C in VS Code.

CamilleHamon avatar Aug 19 '21 13:08 CamilleHamon

I'm on MacOS. I was always able to Copy / Paste image results from the Python interactive window by highlighting/selecting the graphic with the mouse and pressing CTRL+C. However, this functionality seems to have broken in the 1.60 update. I can click+drag the image result into some applications (e.g. an outlook email), but that doesn't work in some other applications (e.g. MS Teams).

ryblogs avatar Sep 03 '21 18:09 ryblogs

For charts, copy CTRL+C not working with 1.60 on windows.

ceaza avatar Sep 10 '21 08:09 ceaza