nteract / hydrogen

:atom: Run code interactively, inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor.
https://nteract.gitbooks.io/hydrogen/
MIT License
3.92k stars 334 forks source link

Copy/save image #245

Open huyiqun opened 8 years ago

huyiqun commented 8 years ago

When I use %inline mode to plot something, it is not possible to copy or save the image, but only to view it in atom. Is it possible to add such functionality or what is the best workaround on this? I currently connect a qtconsole to the existing hydrogen kernel, and run the plot code there in order to directly right click for copying and saving. Just wonder if this is by any chance doable in atom.

Also, a quick related question: when the output is one line, it does not pop up a small window that has option for copying or opening in a file. Can this be changed?

Thanks!

n-riesco commented 8 years ago

On 31/03/16 02:57, huyiqun wrote:

When I use %inline mode to plot something, it is not possible to copy or save the image, but only to view it in atom. Is it possible to add such functionality or what is the best workaround on this? I currently connect a qtconsole to the existing hydrogen kernel, and run the plot code there in order to directly right click for copying and saving. Just wonder if this is by any chance doable in atom.

I think this can be easily done. I'll mark this issue as an enhancement.

Also, a quick related question: when the output is one line, it does not pop up a small window that has option for copying or opening in a file. Can this be changed?

If you click on a one-line bubble, Hydrogen will copy its content to the clipboard.

lgeiger commented 8 years ago

Which language are you using?

For example in python with matplotlib you can do this very easily with plt.savefig('example.pdf')

rgbkrk commented 8 years ago

I'm guessing you're looking for browser style "right-click -> save image"?

screenshot 2016-03-31 07 33 08
huyiqun commented 8 years ago

I am using python and looking for exactly what @rgbkrk has shown. I know saving to a file would be one option, but just wonder if a temporary copy and paste is possible as I am quite used to such functionality. :)

nbara commented 7 years ago

+1 for this!

what @rgbkrk is suggesting is exactly what I am looking for, as I am running my code on a remote notebook, hence plt.savefig() would save the file to the remote computer, not on my local machine...

tobiasbj commented 7 years ago

+1!

weimindong2016 commented 7 years ago

+1! This feature is critical for efficiency improvement when organizing analytics results

holgerbrandl commented 7 years ago

In general it would be great if the plugin would simply allow to save an html copy of the script and the inlined outputs.

duzaichuan commented 7 years ago

+1!

dwSun commented 6 years ago

+1

Earthson commented 6 years ago

+1

rgbkrk commented 6 years ago

I've labeled this as up-for-grabs because no one is known to be working on this yet there are lots of +1s. If you want to tackle it, please do.

It looks like the API you'd want to use is the Atom ContextMenuManager, likely scoping it to .output-area img (or something similar).

bridgesra commented 6 years ago

if you highlight and run both lines:

plt.plot(data)
plt.savefig(path)

with hydrogen, it will save the .png of the plot in the given path. When i did the above, executing them line by line it did not save the fig.

Dirivian commented 6 years ago

+1

kylebarron commented 6 years ago

@rgbkrk Is the transfer of image content to the clipboard a different process than the transfer of text to the clipboard? I.e. is it difficult at all to put onto the clipboard, or is it just not exposed in the UI?

rgbkrk commented 6 years ago

I think it's an Atom thing we have to somehow expose, based on experience with context menus for Electron.

kylebarron commented 6 years ago

I looked a little into the APIs. It appears that Hydrogen currently uses Atom's clipboard API, which seems to only support writing text and not an image.

Atom's clipboard API seems to be separate from Electron's clipboard API, which does allow for writing an image to the clipboard, but it must be a nativeImage, which seems to only allow PNG or JPG formats.

SKalt commented 5 years ago

I was able to get around this by opening the element inspector, selecting the image element, and copying the dataURI to my browser. So long as you have the <img>, you should be able to pass its src into NativeImage.createFromDataUrl to prep the underlying png for export.

bertrandcz commented 5 years ago

+1

jazzlw commented 5 years ago

+1 I was very sad to find out that Jupyter didn't have this functionality...

ttxtea commented 3 years ago

+1 Particularly when working with remote kernels copying images to your clipboard would be tremendously helpful.

mebrunet commented 3 years ago

I've been using a hacky work around for this when working on a remote kernel (and so savefig saves the plots on the server).

  1. Open the inspector (cmd-option-i on Mac)
  2. Select the inspect element icon in the top of the inspection pane (icon is a mouse in a box)
  3. Click on the plot you want to save
  4. Right-click the html item/tag that is now highlighted in the inspection pane (should start with <img alt src="...)
  5. Click copy link address
  6. Paste that address into a new browser tab
  7. Save or copy the plot from there

It's really not ideal, but for one-off plots, I find it faster than saving to your remote server and retrieving via scp.

Screen Shot 2021-03-05 at 3 10 08 PM