8000 Update MovieWriter dpi default by heathhenley · Pull Request #8063 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Update MovieWriter dpi default #8063

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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'.
Expand All @@ -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()

Expand Down
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
0