-
Notifications
You must be signed in to change notification settings - Fork 4
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
Quality-of-life improvements #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@klarh These are very nice quality-of-life improvements. In particular, broadcasting of single-element arrays will be super helpful! Please review these comments, then I think it's good to go.
plato/draw/Scene.py
Outdated
Primitives can also be accessed in the order they were added to | ||
the scene using list-like syntax:: | ||
|
||
first_prim = scene[:3] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first_prim = scene[:3] | |
first_three_prims = scene[:3] |
@@ -1,8 +1,20 @@ | |||
import contextlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this import is separated from the others. Maybe combine this (no empty newline).
plato/draw/matplotlib/Scene.py
Outdated
import matplotlib.pyplot as pp | ||
from matplotlib.collections import PatchCollection | ||
from ... import draw | ||
import numpy as np | ||
|
||
@contextlib.contextmanager | ||
def manage_matplotlib_interactive(): | ||
import matplotlib.pyplot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already imported above -- use pp.isinteractive()
, etc.
@@ -97,4 +109,7 @@ def save(self, filename): | |||
return figure.savefig(filename, dpi=figure.dpi) | |||
|
|||
def _ipython_display_(self): | |||
return self.show() | |||
import IPython.display |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer imports at the top of the module unless this is a "soft" dependency.
plato/draw/pythreejs/Scene.py
Outdated
@@ -180,7 +180,8 @@ def enable(self, name, auto_value=None, **parameters): | |||
|
|||
def show(self): | |||
import IPython |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This imports IPython
while other modules imported IPython.display
.
|
||
self.assertIs(scene[0], prim0) | ||
self.assertIs(scene[-1], prim1) | ||
self.assertEqual(scene[:3], [prim0, prim1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to add one more test line:
self.assertEqual(scene[:3], [prim0, prim1]) | |
self.assertEqual(scene[:2], [prim0, prim1]) | |
self.assertEqual(scene[:3], [prim0, prim1]) |
This change calls IPython.display.display(..., display_id=<>) for many of the types of scenes, which causes jupyter to update the scene if it has been displayed already.
22916e7
to
467c6e5
Compare
Good suggestions, thanks @bdice! |
This should make the broadcasting behavior of the various backends more consistent.
This PR improves the treatment of a few relatively minor issues.
display_id
forIPython.display.display
calls inScene.show()
for many backends. This causes IPython to automatically clear the location where the scene was previously displayed.mesh.unfoldProperties
. This should fix most of the confusion cases when only one particle gets drawn (see pythreejs backend not replicating properties #11), although it isn't the most elegant solution.Scene
objects by integers or slices to get primitives. Part of Quality-of-life improvements #49.