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

Generating images in loop not working #999

Closed
scottwsides opened this issue Oct 1, 2021 · 4 comments
Closed

Generating images in loop not working #999

scottwsides opened this issue Oct 1, 2021 · 4 comments

Comments

@scottwsides
Copy link

scottwsides commented Oct 1, 2021

I've seen the post about getting NGLView to export an image to a PNG file. The example show in NGLView works when changing representations in the same view that is being displayed in a separate cell. The code works for a single view as well. However if I put that code in a loop (I want to make lots of PNGs from different ngl view objects) then the separate view widgets never get displayed and the binary info that is in an object like im0 = view.render_image() ; im0.value--> is empty. Is there ANY way of getting the rendered binary info created without generating the widget. I've tried a number of things to hack this... but unless the viewer is explicitly generated in a separate cell.... the binary image info is not generated. How to fix?

  • Version report
python -c 'import nglview; print(nglview.__version__)' ---> 3.03
python -c 'import ipywidgets; print(ipywidgets.__version__)' ----> 7.6.3
@hainm
Copy link
Collaborator

hainm commented Oct 4, 2021

Is there ANY way of getting the rendered binary info created without generating the widget.

There is no way. You have to display the widget first.
But you can check this code of how to deal with multiple render_image calls. It might give you some ideas.
https://github.com/nglviewer/nglview/blob/master/docs/FAQ.md#how-to-make-nglview-view-object-write-png-file

@hainm
Copy link
Collaborator

hainm commented Oct 4, 2021

You can use from IPython.display import display to programmatically display the view.

for view in [view0, view1]:
    display(view)

@scottwsides
Copy link
Author

scottwsides commented Oct 4, 2021 via email

@hainm
Copy link
Collaborator

hainm commented Oct 5, 2021

Great.

@hainm hainm closed this as completed Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants