8000 Merge pull request #8063 from heath730/Update_MovieWriter_dpi_default · matplotlib/matplotlib@f697e8c · GitHub
[go: up one dir, main page]

Skip to content

Commit f697e8c

Browse files
authored
Merge pull request #8063 from heath730/Update_MovieWriter_dpi_default
[MRG+2] Update MovieWriter dpi default
2 parents 91a2bb8 + e0c002c commit f697e8c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

lib/matplotlib/animation.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,17 @@ class AbstractMovieWriter(six.with_metaclass(abc.ABCMeta)):
155155
'''
156156

157157
@abc.abstractmethod
158-
def setup(self, fig, outfile, dpi):
158+
def setup(self, fig, outfile, dpi=None):
159159
'''
160160
Perform setup for writing the movie file.
161161
162162
fig: `matplotlib.Figure` instance
163163
The figure object that contains the information for frames
164164
outfile: string
165165
The filename of the resulting movie file
166-
dpi: int
166+
dpi: int, optional
167167
The DPI (or resolution) for the file. This controls the size
168-
in pixels of the resulting movie file.
168+
in pixels of the resulting movie file. Default is fig.dpi.
169169
'''
170170

171171
@abc.abstractmethod
@@ -281,7 +281,7 @@ def _adjust_frame_size(self):
281281
verbose.report('frame size in pixels is %s x %s' % self.frame_size,
282282
level='debug')
283283

284-
def setup(self, fig, outfile, dpi):
284+
def setup(self, fig, outfile, dpi=None):
285285
'''
286286
Perform setup for writing the movie file.
287287
@@ -292,12 +292,14 @@ def setup(self, fig, outfile, dpi):
292292
The figure object that contains the information for frames
293293
outfile : string
294294
The filename of the resulting movie file
295-
dpi : int
295+
dpi : int, optional
296296
The DPI (or resolution) for the file. This controls the size
297-
in pixels of the resulting movie file.
297+
in pixels of the resulting movie file. Default is fig.dpi.
298298
'''
299299
self.outfile = outfile
300300
self.fig = fig
301+
if dpi is None:
302+
dpi = self.fig.dpi
301303
self.dpi = dpi
302304
self._adjust_frame_size()
303305

@@ -404,7 +406,8 @@ def __init__(self, *args, **kwargs):
404406
MovieWriter.__init__(self, *args, **kwargs)
405407
self.frame_format = rcParams['animation.frame_format']
406408

407-
def setup(self, fig, outfile, dpi, frame_prefix='_tmp', clear_temp=True):
409+
def setup(self, fig, outfile, dpi=None, frame_prefix='_tmp',
410+
clear_temp=True):
408411
'''Perform setup for writing the movie file.
409412
410413
Parameters
@@ -413,9 +416,10 @@ def setup(self, fig, outfile, dpi, frame_prefix='_tmp', clear_temp=True):
413416
The figure to grab the rendered frames from.
414417
outfile : str
415418
The filename of the resulting movie file.
416-
dpi : number
419+
dpi : number, optional
417420
The dpi of the output file. This, with the figure size,
418421
controls the size in pixels of the resulting movie file.
422+
Default is fig.dpi.
419423
frame_prefix : str, optional
420424
The filename prefix to use for temporary files. Defaults to
421425
'_tmp'.
@@ -427,6 +431,8 @@ def setup(self, fig, outfile, dpi, frame_prefix='_tmp', clear_temp=True):
427431
'''
428432
self.fig = fig
429433
self.outfile = outfile
434+
if dpi is None:
435+
dpi = self.fig.dpi
430436
self.dpi = dpi
431437
self._adjust_frame_size()
432438

lib/matplotlib/tests/test_animation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ def animate(i):
7474
assert writer._count == num_frames
7575

7676

77+
def test_movie_writer_dpi_default():
78+
# Test setting up movie writer with figure.dpi default.
79+
80+
fig = plt.figure()
81+
82+
filename = "unused.null"
83+
fps = 5
84+
codec = "unused"
85+
bitrate = 1
86+
extra_args = ["unused"]
87+
88+
def run():
89+
pass
90+
91+
writer = animation.MovieWriter(fps, codec, bitrate, extra_args)
92+
writer._run = run
93+
writer.setup(fig, filename)
94+
assert writer.dpi == fig.dpi
95+
96+
7797
@animation.writers.register('null')
7898
class RegisteredNullMovieWriter(NullMovieWriter):
7999

0 commit comments

Comments
 (0)
0