Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a507300

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

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

lib/matplotlib/animation.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,31 @@
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+
'''Adjust figure size to be multiple of n
7267
68+
Parameters
69+
----------
70+
h, w : float
71+
Size in inches
72+
73+
dpi : float
74+
The dpi
75+
76+
n : int
77+
The target multiple
78+
'''
79+
80+
# this maybe simplified if / when we adopt consistent rounding for
81+
# pixel size across the whole library
82+
def correct_roundoff(x, dpi, n):
83+
if int(x*dpi) % n != 0:
84+
if int(np.nextafter(x, np.inf)*dpi) % n == 0:
85+
x = np.nextafter(x, np.inf)
86+
elif int(np.nextafter(x, -np.inf)*dpi) % n == 0:
87+
x = np.nextafter(x, -np.inf)
88+
return x
7389

74-
def adjusted_figsize(w, h, dpi, n):
7590
wnew = int(w * dpi / n) * n / dpi
7691
hnew = int(h * dpi / n) * n / dpi
7792
return (correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n))
@@ -350,6 +365,9 @@ def grab_frame(self, **savefig_kwargs):
350365
verbose.report('MovieWriter.grab_frame: Grabbing frame.',
351366
level='debug')
352367
try:
368+
# re-adjust the figure size in case it has been changed by the
369+
# user. We must ensure that every frame is the same size or
370+
# the movie will not save correctly.
353371
self.fig.set_size_inches(self._w, self._h)
354372
# Tell the figure to save its data to the sink, using the
355373
# frame format and dpi.

0 commit comments

Comments
 (0)