-
Notifications
You must be signed in to change notification settings - Fork 105
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
Added CallbackMovie #1544
Added CallbackMovie #1544
Conversation
Code for odlgroup#1135
Checking updated PR...
Comment last updated at 2020-03-30 19:01:09 UTC |
I don't quite know how to properly handle the docstring tests. Any ideas?
What is the minimum supported Python2 version? If it is 2.5 or below we need |
Errors have meaningfull messages Added __repr__, but need help with parameters that are consumed by Matplotlib.animation Changed codec in docstring, so maybe pytest can cope with this one
No, the minimum is 2.7. See here: Lines 30 to 35 in 0d06b07
and here: Line 46 in 0d06b07
|
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.
Thanks for your contribution @miallo. This callback can certainly be useful in many situations.
But in the current implementation as a single class, I think that too much unrelated functionality is tied up in one place. The class has trouble managing its own state correctly and must use some weird logic to avoid wrong usage.
My suggestion would be to pull the context manager out of the class and make it a free context manager that provides a callback when entered. Like so:
@contextlib.contextmanager
def save_animation(writer):
# Init code
writer = ...
im = ...
class CallbackAppendMovieFrame(Callback):
def __call__(self, x):
# Do something with x
im.set_array(...)
writer.grab_frame()
def __repr__(self):
# Not so important anymore since the class cannot
# be instantiated directly anyway
try:
with writer.saving(...):
yield CallbackAppendMovieFrame()
finally:
# Whatever needs to be finalized, closed, ...
This way, the callback can only be used in the intended way.
Whether the figure should be created outside or in the context manager I don't really know yet. I guess most of the time one would use this with the agg
backend anyway that doesn't show anything on screen. Is there a specific reason you put it outside in the current implementation, @miallo?
One thing to consider is: if users type
I did this to easily set up the colormap, and x/y-limits inside the |
But also not the worst :-) That said, I'd still advocate the standalone context manager.
Ah I see. Indeed, global settings can be modified outside using matplotlib |
The current implementation of the whole callback only works for (2D-)images - if it was used for 1D plots as well, there are a couple of things that had to be changed...
Now I remember the main reason why I did this: I cannot create a |
Thanks for the update, looking very promising.
I think it's fine for now to only support the most relevant case. To make that clearer, the callback could raise a
Ah, that makes sense. I don't think the workaround is that bad, though. To make it even nicer, you could move the try:
im = ax.get_images()[-1]
except IndexError:
im = ax.imshow(x) That would remove the necessity to overwrite a BTW, we don't have to create a |
A |
Good point, let's stick to |
I extracted What else needs to be done? |
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.
Some comments and suggestions mostly on documentation and style. Functionality-wise I think we're good, looks nice and clean.
(We're in the nit phase now 😉 ).
- Use first available writer by default instead of fixed one - Use figure DPI by default, otherwise create figure with given DPI - Documentation fixes, mostly by linking to MPL docs - Simplify implementation of CallbackAppendFrame
I pushed a few doc and default behavior improvements, after that I'll merge. |
Code for #1135