Update MovieWriter dpi default #8063

Merged
merged 2 commits into from Feb 16, 2017
@@ -155,17 +155,17 @@ class AbstractMovieWriter(six.with_metaclass(abc.ABCMeta)):
'''
@abc.abstractmethod
- def setup(self, fig, outfile, dpi):
+ def setup(self, fig, outfile, dpi=None):
'''
Perform setup for writing the movie file.
fig: `matplotlib.Figure` instance
The figure object that contains the information for frames
outfile: string
The filename of the resulting movie file
- dpi: int
+ dpi: int, optional
The DPI (or resolution) for the file. This controls the size
- in pixels of the resulting movie file.
+ in pixels of the resulting movie file. Default is fig.dpi.
'''
@abc.abstractmethod
@@ -281,7 +281,7 @@ def _adjust_frame_size(self):
verbose.report('frame size in pixels is %s x %s' % self.frame_size,
level='debug')
- def setup(self, fig, outfile, dpi):
+ def setup(self, fig, outfile, dpi=None):
'''
Perform setup for writing the movie file.
@@ -292,12 +292,14 @@ def setup(self, fig, outfile, dpi):
The figure object that contains the information for frames
outfile : string
The filename of the resulting movie file
- dpi : int
+ dpi : int, optional
The DPI (or resolution) for the file. This controls the size
- in pixels of the resulting movie file.
+ in pixels of the resulting movie file. Default is fig.dpi.
'''
self.outfile = outfile
self.fig = fig
+ if dpi is None:
+ dpi = self.fig.dpi
self.dpi = dpi
self._adjust_frame_size()
@@ -404,7 +406,8 @@ def __init__(self, *args, **kwargs):
MovieWriter.__init__(self, *args, **kwargs)
self.frame_format = rcParams['animation.frame_format']
- def setup(self, fig, outfile, dpi, frame_prefix='_tmp', clear_temp=True):
+ def setup(self, fig, outfile, dpi=None, frame_prefix='_tmp',
+ clear_temp=True):
'''Perform setup for writing the movie file.
Parameters
@@ -413,9 +416,10 @@ def setup(self, fig, outfile, dpi, frame_prefix='_tmp', clear_temp=True):
The figure to grab the rendered frames from.
outfile : str
The filename of the resulting movie file.
- dpi : number
+ dpi : number, optional
The dpi of the output file. This, with the figure size,
controls the size in pixels of the resulting movie file.
+ Default is fig.dpi.
frame_prefix : str, optional
The filename prefix to use for temporary files. Defaults to
'_tmp'.
@@ -427,6 +431,8 @@ def setup(self, fig, outfile, dpi, frame_prefix='_tmp', clear_temp=True):
'''
self.fig = fig
self.outfile = outfile
+ if dpi is None:
+ dpi = self.fig.dpi
self.dpi = dpi
self._adjust_frame_size()
@@ -74,6 +74,26 @@ def animate(i):
assert writer._count == num_frames
+def test_movie_writer_dpi_default():
+ # Test setting up movie writer with figure.dpi default.
+
+ fig = plt.figure()
+
+ filename = "unused.null"
+ fps = 5
+ codec = "unused"
+ bitrate = 1
+ extra_args = ["unused"]
+
+ def run():
+ pass
+
+ writer = animation.MovieWriter(fps, codec, bitrate, extra_args)
+ writer._run = run
+ writer.setup(fig, filename)
+ assert writer.dpi == fig.dpi
+
+
@animation.writers.register('null')
class RegisteredNullMovieWriter(NullMovieWriter):