MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / adjusted_figsize

Function adjusted_figsize

lib/matplotlib/animation.py:33–66  ·  view source on GitHub ↗

Compute figure size so that pixels are a multiple of n. Parameters ---------- w, h : float Size in inches. dpi : float The dpi. n : int The target multiple. Returns ------- wnew, hnew : float The new figure size in inches.

(w, h, dpi, n)

Source from the content-addressed store, hash-verified

31
32
33def adjusted_figsize(w, h, dpi, n):
34 """
35 Compute figure size so that pixels are a multiple of n.
36
37 Parameters
38 ----------
39 w, h : float
40 Size in inches.
41
42 dpi : float
43 The dpi.
44
45 n : int
46 The target multiple.
47
48 Returns
49 -------
50 wnew, hnew : float
51 The new figure size in inches.
52 """
53
54 # this maybe simplified if / when we adopt consistent rounding for
55 # pixel size across the whole library
56 def correct_roundoff(x, dpi, n):
57 if int(x*dpi) % n != 0:
58 if int(np.nextafter(x, np.inf)*dpi) % n == 0:
59 x = np.nextafter(x, np.inf)
60 elif int(np.nextafter(x, -np.inf)*dpi) % n == 0:
61 x = np.nextafter(x, -np.inf)
62 return x
63
64 wnew = int(w * dpi / n) * n / dpi
65 hnew = int(h * dpi / n) * n / dpi
66 return correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n)
67
68
69class MovieWriterRegistry:

Callers 1

_adjust_frame_sizeMethod · 0.85

Calls 1

correct_roundoffFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…