-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add extra.utils.imshow2 for easier image plotting #38
Conversation
src/extra/utils/misc.py
Outdated
# Try to avoid repeatedly importing matplotlib by looking in sys.modules | ||
# first. | ||
if "matplotlib.pyplot" in sys.modules: | ||
plt = sys.modules["matplotlib.pyplot"] | ||
else: | ||
import matplotlib.pyplot as plt |
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.
# Try to avoid repeatedly importing matplotlib by looking in sys.modules | |
# first. | |
if "matplotlib.pyplot" in sys.modules: | |
plt = sys.modules["matplotlib.pyplot"] | |
else: | |
import matplotlib.pyplot as plt | |
import matplotlib.pyplot as plt |
Importing something a second time is cheap - it's basically just doing the same lookup in sys.modules
that you do here. So there's no need to complicate it. 🙂
In [1]: %time import matplotlib
CPU times: user 257 ms, sys: 235 ms, total: 492 ms
Wall time: 445 ms
In [2]: %time import matplotlib
CPU times: user 21 µs, sys: 0 ns, total: 21 µs
Wall time: 32.2 µs
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.
Ah cool, I thought it would re-import the whole thing. Fixed in 7906c54.
src/extra/utils/misc.py
Outdated
|
||
ax = plt | ||
|
||
imshow_kwargs = dict(interpolation="none") |
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.
Should the docstring mention this too?
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.
Whoops, yes 🙈 Added in 7906c54.
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.
Oh yes, this looks like it may save some time regularly. Not a fan of the name, but I also don't got any other ideas.
Nothing to complain, just an idea: I regularly use norm=LogNorm()
and always forget to add from matplotlib.colors import LogNorm
. Maybe extend the interface by some lognorm=True
option?
Still LGTM.
Good idea, added in b66a3e8 👍 |
I wrote this function ages ago and I'm constantly copying it over to new notebooks, so I figured it might be useful to put here.