Raise a ValueError if the figure *num* already exists.
(num, func_name, clear=False)
| 1184 | |
| 1185 | |
| 1186 | def _raise_if_figure_exists(num, func_name, clear=False): |
| 1187 | """ |
| 1188 | Raise a ValueError if the figure *num* already exists. |
| 1189 | """ |
| 1190 | if num is not None and not clear: |
| 1191 | if isinstance(num, FigureBase): |
| 1192 | raise ValueError( |
| 1193 | f"num {num!r} cannot be a FigureBase instance. " |
| 1194 | f"plt.{func_name}() is for creating new figures. " |
| 1195 | f"To add to an existing figure, use fig.{func_name}() " |
| 1196 | "instead.") |
| 1197 | |
| 1198 | if fignum_exists(num): |
| 1199 | raise ValueError( |
| 1200 | f"Figure {num!r} already exists. Use plt.figure({num!r}) " |
| 1201 | f"to get it or plt.close({num!r}) to close it. " |
| 1202 | f"Alternatively, pass 'clear=True' to {func_name}().") |
| 1203 | |
| 1204 | |
| 1205 | def get_fignums() -> list[int]: |
no test coverage detected
searching dependent graphs…