Skip to content

Use rounding instead of truncation to calculate the frame size #8250

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def __init__(self, fps=5, codec=None, bitrate=None, extra_args=None,
def frame_size(self):
'A tuple (width,height) in pixels of a movie frame.'
w, h = self.fig.get_size_inches()
return int(w * self.dpi), int(h * self.dpi)
return round(w * self.dpi), round(h * self.dpi)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use np.round? Otherwise, the behavior is Python version-dependent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity to Nathan, you mean np.round([w * self.dpi, h * self.dpi]), right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(tuple of numpy scalars vs numpy array)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result (according to the docstring) should still be a tuple.


def _adjust_frame_size(self):
if self.codec == 'h264':
Expand Down