(title: str, output: str, background: str, tight: bool = True)
| 52 | |
| 53 | |
| 54 | def deploy_plot(title: str, output: str, background: str, tight: bool = True) -> None: |
| 55 | import matplotlib.pyplot as pyplot |
| 56 | |
| 57 | if not output: |
| 58 | pyplot.gcf().canvas.set_window_title(title) |
| 59 | pyplot.show() |
| 60 | else: |
| 61 | po = Path(output) |
| 62 | if len(po.name) > 64: |
| 63 | suffix = po.suffix[:5] |
| 64 | output = str(po.with_name(po.stem[:64 - len(suffix)] + suffix)) |
| 65 | if title: |
| 66 | pyplot.title(title, color="black" if background == "white" else "white") |
| 67 | if tight: |
| 68 | try: |
| 69 | pyplot.tight_layout() |
| 70 | except: # noqa: E722 |
| 71 | print("Warning: failed to set the tight layout") |
| 72 | print("Writing plot to %s" % output) |
| 73 | pyplot.savefig(output, transparent=True) |
| 74 | pyplot.clf() |
no outgoing calls
no test coverage detected