Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying an image result from Python Interactive window #1470

Closed
andrewdelong opened this issue Jan 24, 2019 · 32 comments
Closed

Allow copying an image result from Python Interactive window #1470

andrewdelong opened this issue Jan 24, 2019 · 32 comments
Assignees
Labels
feature-request Request for new features or functionality interactive-window Impacts interactive window notebook-workflow Issues that interrupt expected or desirable behavior

Comments

@andrewdelong
Copy link

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.
@IanMatthewHuff
Copy link
Member

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.

@andrewdelong
Copy link
Author

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

@IanMatthewHuff
Copy link
Member

IanMatthewHuff commented Jan 25, 2019

@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
Copy link
Member

IanMatthewHuff commented Jan 25, 2019

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
Copy link
Member

@rchiodo
Copy link
Contributor

rchiodo commented Mar 5, 2019

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

@stmax82
Copy link

stmax82 commented Apr 15, 2019

@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.

@IanMatthewHuff
Copy link
Member

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

@stmax82
Copy link

stmax82 commented Apr 25, 2019

@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.

@IanMatthewHuff
Copy link
Member

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.

@greazer
Copy link
Member

greazer commented Jun 6, 2019

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

@rchiodo
Copy link
Contributor

rchiodo commented Jun 11, 2019

This isn't possible without this working:
microsoft/vscode#217

@dpsugasa
Copy link

dpsugasa commented Sep 6, 2019

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

@rchiodo
Copy link
Contributor

rchiodo commented Sep 6, 2019

@dpsugasa the export button should allow you to save as PDF/PNG. That was working until this change:
microsoft/vscode-python#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.

@alext234
Copy link

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

@michaelberks
Copy link

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)?

@rchiodo
Copy link
Contributor

rchiodo commented Dec 6, 2019

@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.

@michaelberks
Copy link

michaelberks commented Dec 6, 2019

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!

@rstoddard24
Copy link

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)

@andreimargeloiu
Copy link

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

@berkdemir
Copy link

Any development on this issue?

@rchiodo
Copy link
Contributor

rchiodo commented Feb 3, 2021

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
Copy link
Contributor

rchiodo commented Feb 3, 2021

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

@berkdemir
Copy link

berkdemir commented Feb 3, 2021 via email

@greazer
Copy link
Member

greazer commented Feb 4, 2021

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

@linzhlalala
Copy link

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

@ceronvgabriel
Copy link

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.

@greazer greazer added interactive-window Impacts interactive window and removed P2 labels Jul 26, 2021
@greazer greazer added the notebook-workflow Issues that interrupt expected or desirable behavior label Aug 4, 2021
@CamilleHamon
Copy link

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.

@ryblogs
Copy link

ryblogs commented Sep 3, 2021

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).

@ceaza
Copy link

ceaza commented Sep 10, 2021

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

@bpops
Copy link

bpops commented Sep 13, 2021

I didn't want to create a new issue, but it appears some of the functionality discussed herein is further broken in the new vs code notebooks. Also, my main way of using plots before, dragging them out of vs code directly into powerpoint, no longer works. I must drag them into a windows explorer folder and then into powerpoint.

@amunger
Copy link
Contributor

amunger commented Aug 12, 2022

A copy to clipboard feature was added to the renderer in microsoft/vscode#129880

@amunger amunger closed this as completed Aug 12, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality interactive-window Impacts interactive window notebook-workflow Issues that interrupt expected or desirable behavior
Projects
None yet
Development

No branches or pull requests