-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create figure in current directory #273
Create figure in current directory #273
Conversation
@@ -295,7 +295,8 @@ def run_likelihood() -> None: | |||
[a.legend(fontsize="small") for a in ax] | |||
|
|||
fig.suptitle("PT Cls, including IA, galaxy bias, magnification") | |||
fig.savefig("plots/pt_cls.png", facecolor="white", dpi=300) | |||
with open("pt_cls.png", "w+b") as png_file: | |||
fig.savefig(png_file, facecolor="white", dpi=300) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the context manager instead of using the file name directly in savefig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Habit. I prefer to make it obvious the resource is “cleaned up” (in this case, the file closed) rather than having a reader need to know whether the routine being called does the right thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's just here that fine but generally I'd argue having a context manager for savefig
is overkill and likely to confuse users (what happens if you forget the "b"
?). Might as well throw in a os.makedirs("plots", exists_ok=True)
to deal with the subdir in that case.
@@ -295,7 +295,8 @@ def run_likelihood() -> None: | |||
[a.legend(fontsize="small") for a in ax] | |||
|
|||
fig.suptitle("PT Cls, including IA, galaxy bias, magnification") | |||
fig.savefig("plots/pt_cls.png", facecolor="white", dpi=300) | |||
with open("pt_cls.png", "w+b") as png_file: | |||
fig.savefig(png_file, facecolor="white", dpi=300) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's just here that fine but generally I'd argue having a context manager for savefig
is overkill and likely to confuse users (what happens if you forget the "b"
?). Might as well throw in a os.makedirs("plots", exists_ok=True)
to deal with the subdir in that case.
This fixes the issue by creating the figure in the current directory, which was simpler than creating a subdirectory.