-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: single plane plotting framework
- Loading branch information
Showing
3 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pathlib | ||
import re | ||
|
||
import matplotlib | ||
import matplotlib.pyplot as plt | ||
import pytest | ||
|
||
matplotlib.use("Agg") | ||
|
||
test_root = pathlib.Path(__file__).parent.resolve() | ||
test_artifacts = test_root / "artifacts" | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="function") | ||
def _plot_show_to_savefig( | ||
request: pytest.FixtureRequest, | ||
monkeypatch: pytest.MonkeyPatch, | ||
): | ||
index = 0 | ||
|
||
def savefig(): | ||
nonlocal index | ||
test_artifacts.mkdir(exist_ok=True) | ||
for fignum in plt.get_fignums(): | ||
plt.figure(fignum) | ||
name = re.sub(r"[/\\]", "_", request.node.name) | ||
filename = test_artifacts / f"{name}_{index}.png" | ||
print(f"Saving figure (_plot_show_to_savefig fixture) to {filename}") | ||
plt.savefig(filename) | ||
index += 1 | ||
plt.close("all") | ||
|
||
monkeypatch.setattr(plt, "show", savefig) | ||
yield | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters