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)
| 31 | |
| 32 | |
| 33 | def 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 | |
| 69 | class MovieWriterRegistry: |
no test coverage detected
searching dependent graphs…