Skip to content

Handle floating point round-off error when converting to pixels for h264 animations #8253

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

Merged
merged 7 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test for movie writing floating point roundoff issues
  • Loading branch information
Nathan Goldbaum committed Mar 13, 2017
commit 08eb4347aacc48a856627720bc73350f4379e08a
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ addons:
packages:
- inkscape
- libav-tools
- libavcodec-extra-53
- gdb
- mencoder
- dvipng
Expand Down
7 changes: 5 additions & 2 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ def _adjust_frame_size(self):
verbose.report('figure size (inches) has been adjusted '
'from %s x %s to %s x %s' % (wo, ho, w, h),
level='helpful')
else:
w, h = self.fig.get_size_inches()
verbose.report('frame size in pixels is %s x %s' % self.frame_size,
level='debug')
return w, h

def setup(self, fig, outfile, dpi=None):
'''
Expand All @@ -311,7 +314,7 @@ def setup(self, fig, outfile, dpi=None):
if dpi is None:
dpi = self.fig.dpi
self.dpi = dpi
self._adjust_frame_size()
self._w, self._h = self._adjust_frame_size()

# Run here so that grab_frame() can write the data to a pipe. This
# eliminates the need for temp files.
Expand Down Expand Up @@ -347,7 +350,7 @@ def grab_frame(self, **savefig_kwargs):
verbose.report('MovieWriter.grab_frame: Grabbing frame.',
level='debug')
try:
self._adjust_frame_size()
self.fig.set_size_inches(self._w, self._h)
# Tell the figure to save its data to the sink, using the
# frame format and dpi.
self.fig.savefig(self._frame_sink(), format=self.frame_format,
Expand Down
11 changes: 10 additions & 1 deletion lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ def test_save_animation_smoketest(tmpdir, writer, extension):
ax.set_xlim(0, 10)
ax.set_ylim(-1, 1)

dpi = None
codec = None
if writer == 'ffmpeg':
# Issue #8253
fig.set_size_inches((10.85, 9.2000000000000011))
dpi = 100.
codec = 'h264'

def init():
line.set_data([], [])
return line,
Expand All @@ -160,7 +168,8 @@ def animate(i):
with tmpdir.as_cwd():
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=5)
try:
anim.save('movie.' + extension, fps=30, writer=writer, bitrate=500)
anim.save('movie.' + extension, fps=30, writer=writer, bitrate=500,
dpi=dpi, codec=codec)
except UnicodeDecodeError:
pytest.xfail("There can be errors in the numpy import stack, "
"see issues #1891 and #2679")
Expand Down