GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `figure.export()` usage outside of a notebook · Issue #714 · fastplotlib/fastplotlib

figure.export() usage outside of a notebook #714

New issue
Copy link
New issue
Copy link
Open
Open
figure.export() usage outside of a notebook#714
Copy link

Description

@FlynnOConnell
FlynnOConnell
opened on Jan 30, 2025
Issue body actions

figure.export() will only work if show() is called first and export() is called in a separate cell.

This works:

import fastplotlib as fpl
import numpy as np

random_3d = np.random.randn(100, 100, 100)
iw = fpl.ImageWidget(data=random_3d)
iw.show()

Image

iw.figure.export('./random.png')

Image

This does not:

import fastplotlib as fpl
import numpy as np

random_3d = np.random.randn(100, 100, 100)
iw = fpl.ImageWidget(data=random_3d)
iw.show()
iw.figure.export('./random.png')
iw.close()

AttributeError                            Traceback (most recent call last)
Cell In[12], line 9
      7 iw = lcp.plot_contours(cnmf_df, -1)
      8 iw.show()
----> 9 iw.figure.export('./test.png')
     10 iw.close()
     12 # lcp.save_contours(cnmf_df, -1, './test.png')

File [~/miniforge3/envs/lcp/lib/python3.10/site-packages/fastplotlib/layouts/_figure.py:596](http://localhost:8888/home/flynn/miniforge3/envs/lcp/lib/python3.10/site-packages/fastplotlib/layouts/_figure.py#line=595), in Figure.export(self, uri, **kwargs)
    590     raise ImportError(
    591         "imageio is required to use Figure.export(). Install it using pip or conda:\n"
    592         "pip install imageio\n"
    593         "conda install -c conda-forge imageio\n"
    594     )
    595 else:
--> 596     snapshot = self.renderer.snapshot()
    597     remove_alpha = True
    599     # image formats that support alpha channel:
    600     # https://en.wikipedia.org/wiki/Alpha_compositing#Image_formats_supporting_alpha_channels

File ~/miniforge3/envs/lcp/lib/python3.10/site-packages/pygfx/renderers/wgpu/engine/renderer.py:789, in WgpuRenderer.snapshot(self)
    786 """Create a snapshot of the currently rendered image."""
    788 # Prepare
--> 789 texture = self._blender.color_tex
    790 size = texture.size
    791 bytes_per_pixel = 4

AttributeError: 'Ordered2FragmentBlender' object has no attribute 'color_tex'

This is more of an issue when I have built an image widget in a separate function, I'd like to save a image of the widget before returning it to the user without needing to render it.

Is this possible?

Activity

  1. kushalkolar commented on Jan 30, 2025

    @kushalkolar
    kushalkolar
    on Jan 30, 2025
    Member
    More actions

    The show calls starts the rendering so this isn't possible. In the future when we take advantage of the new features in rendercanvas you can force one render and then take a screenshot.

  2. kushalkolar commented on Jan 30, 2025

    @kushalkolar
    kushalkolar
    on Jan 30, 2025
    Member
    More actions

    related, see #710 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.