Set the figure size in inches. Call signatures:: fig.set_size_inches(w, h) # OR fig.set_size_inches((w, h)) Parameters ---------- w : (float, float) or float Width and height in inches (if height not specified as a se
(self, w, h=None, forward=True)
| 3127 | return im |
| 3128 | |
| 3129 | def set_size_inches(self, w, h=None, forward=True): |
| 3130 | """ |
| 3131 | Set the figure size in inches. |
| 3132 | |
| 3133 | Call signatures:: |
| 3134 | |
| 3135 | fig.set_size_inches(w, h) # OR |
| 3136 | fig.set_size_inches((w, h)) |
| 3137 | |
| 3138 | Parameters |
| 3139 | ---------- |
| 3140 | w : (float, float) or float |
| 3141 | Width and height in inches (if height not specified as a separate |
| 3142 | argument) or width. |
| 3143 | h : float |
| 3144 | Height in inches. |
| 3145 | forward : bool, default: True |
| 3146 | If ``True``, the canvas size is automatically updated, e.g., |
| 3147 | you can resize the figure window from the shell. |
| 3148 | |
| 3149 | See Also |
| 3150 | -------- |
| 3151 | matplotlib.figure.Figure.get_size_inches |
| 3152 | matplotlib.figure.Figure.set_figwidth |
| 3153 | matplotlib.figure.Figure.set_figheight |
| 3154 | |
| 3155 | Notes |
| 3156 | ----- |
| 3157 | To transform from pixels to inches divide by `Figure.dpi`. |
| 3158 | """ |
| 3159 | if h is None: # Got called with a single pair as argument. |
| 3160 | w, h = w |
| 3161 | if w is None or h is None: |
| 3162 | raise ValueError( |
| 3163 | "Figure.set_size_inches does not accept None; provide both " |
| 3164 | "width and height explicitly") |
| 3165 | size = np.array([w, h]) |
| 3166 | if not np.isfinite(size).all() or (size < 0).any(): |
| 3167 | raise ValueError(f'figure size must be positive finite not {size}') |
| 3168 | self.bbox_inches.p1 = size |
| 3169 | if forward: |
| 3170 | manager = self.canvas.manager |
| 3171 | if manager is not None: |
| 3172 | manager.resize(*(size * self.dpi).astype(int)) |
| 3173 | self.stale = True |
| 3174 | |
| 3175 | def get_size_inches(self): |
| 3176 | """ |