nteract / scrapbook

A library for recording and reading data in notebooks.
https://nteract-scrapbook.readthedocs.io
BSD 3-Clause "New" or "Revised" License
281 stars 26 forks source link

Cool project, however, some suggestions for improvements #80

Open anaderi opened 3 years ago

anaderi commented 3 years ago
  1. it is not obvious how to display a saved display (image)...
  2. There is a an unnecessary ambiguity for the word 'display' here. it denotes type of scrap as well as scrap output flag upon saving
  3. as I glue a display, it is always shown twice. plt.ioff() doesn't help.

here is the snippet for displaying image:

def display_image_scrap(nb, key):

    def stringToRGB(base64_string):
        imgdata = base64.b64decode(base64_string)
        image = Image.open(io.BytesIO(imgdata))
        return image

    image = stringToRGB(nb.scraps[key].display['data']['image/png'])
    imsize_inches = (np.array(image.size) / 70).astype('int8').tolist()

    fig = plt.figure(figsize=imsize_inches)
    ax = fig.add_axes([0, 0, 1, 1])
    ax.imshow(np.array(image), interpolation='antialiased')
    plt.axis('off')

due to (3) I had to disable image scraping for the moment. :(

MSeal commented 3 years ago
  • it is not obvious how to display a saved display (image)...

Yeah I'd like to improve the contract here to make it better but still easy to use. Happy to hear suggestions.

  • There is a an unnecessary ambiguity for the word 'display' here. it denotes type of scrap as well as scrap output flag upon saving

This comes from the encoder having the 'display' name as well as the contents of the scrap having a display attribute since the visual is independent of the data that generated said visual. Maybe 'display-only' encoder would be clearer naming convention?

  • as I glue a display, it is always shown twice. plt.ioff() doesn't help.

That sounds like a bug that needs investigating

oakaigh commented 11 months ago

@MSeal

it is not obvious how to display a saved display (image)...

Since the latest version of matplotlib officially supports pickling, using a pickle-r to encode the whole matplotlib figure could solve the problem. See #91 for implementations and more.