Skip to content

Commit 5d4f5de

Browse files
committed
DOC/MNT : add docs + make helper function private
1 parent f287ac6 commit 5d4f5de

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

lib/matplotlib/animation.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,36 @@
6262
# how-to-encode-series-of-images-into-h264-using-x264-api-c-c )
6363

6464

65-
def correct_roundoff(x, dpi, n):
66-
if int(x*dpi) % n != 0:
67-
if int(np.nextafter(x, np.inf)*dpi) % n == 0:
68-
x = np.nextafter(x, np.inf)
69-
elif int(np.nextafter(x, -np.inf)*dpi) % n == 0:
70-
x = np.nextafter(x, -np.inf)
71-
return x
65+
def adjusted_figsize(w, h, dpi, n):
66+
'''Compute figure size so that pixels are a multiple of n
7267
68+
Parameters
69+
----------
70+
w, h : float
71+
Size in inches
72+
73+
dpi : float
74+
The dpi
75+
76+
n : int
77+
The target multiple
78+
79+
Returns
80+
-------
81+
wnew, hnew : float
82+
The new figure size in inches.
83+
'''
84+
85+
# this maybe simplified if / when we adopt consistent rounding for
86+
# pixel size across the whole library
87+
def correct_roundoff(x, dpi, n):
88+
if int(x*dpi) % n != 0:
89+
if int(np.nextafter(x, np.inf)*dpi) % n == 0:
90+
x = np.nextafter(x, np.inf)
91+
elif int(np.nextafter(x, -np.inf)*dpi) % n == 0:
92+
x = np.nextafter(x, -np.inf)
93+
return x
7394

74-
def adjusted_figsize(w, h, dpi, n):
7595
wnew = int(w * dpi / n) * n / dpi
7696
hnew = int(h * dpi / n) * n / dpi
7797
return (correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n))
@@ -350,6 +370,9 @@ def grab_frame(self, **savefig_kwargs):
350370
verbose.report('MovieWriter.grab_frame: Grabbing frame.',
351371
level='debug')
352372
try:
373+
# re-adjust the figure size in case it has been changed by the
374+
# user. We must ensure that every frame is the same size or
375+
# the movie will not save correctly.
353376
self.fig.set_size_inches(self._w, self._h)
354377
# Tell the figure to save its data to the sink, using the
355378
# frame format and dpi.

0 commit comments

Comments
 (0)