-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Introducing astro_support, to enable time_support and quantity_support simultaneously #17575
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
Changes from all commits
3819d1b
c18fd55
98437d3
c98b236
5d730bf
ae1d1ff
07ada01
9a100e5
520529e
60208c2
a1d03c8
4d82d36
b8b402c
4f860cc
ba1c660
3ad0c25
277e452
235bd4e
43652b8
9f00dc1
667f457
8f32067
44f5abf
5830e98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,5 +55,6 @@ | |
| "astropy.visualization.wcsaxes.tests.test_transform_coord_meta.TestTransformCoordMeta.test_coords_overlay_auto_coord_meta": "2f737bb70fb1a5452cb0efa79010376614dc559e9aff607f638f044ac6b04448", | ||
| "astropy.visualization.wcsaxes.tests.test_transform_coord_meta.TestTransformCoordMeta.test_direct_init": "1f24c5243bfdf0f30e88afc4f2f5d66db85954cea50a2910af94975ff8765b45", | ||
| "astropy.visualization.wcsaxes.tests.test_wcsapi.test_wcsapi_5d_with_names": "c90ae6f3b0f9f407ca7a866fa648dc3ef4bea78369315292bc82f16104ed5736", | ||
| "astropy.visualization.wcsaxes.tests.test_wcsapi.test_wcsapi_2d_celestial_arcsec": "4b743d645a85d7516decbcf4a831c127af5a1800072597c2a1299d17fb186adb" | ||
| "astropy.visualization.wcsaxes.tests.test_wcsapi.test_wcsapi_2d_celestial_arcsec": "4b743d645a85d7516decbcf4a831c127af5a1800072597c2a1299d17fb186adb", | ||
| "astropy.visualization.wcsaxes.tests.test_images.test_astropy_support": "aee3dd8cfc0998ec2d904549c6527fa55f3b16cbe9a30c222a2c0ac6a6db155e" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as https://github.com/astropy/astropy/pull/17575/files#r1904638767 |
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot find any mention of this new module in https://astropy--17575.org.readthedocs.build/en/17575/visualization/ref_api.html , so none of this docstring is actually being rendered. You might need to modify https://github.com/astropy/astropy/blob/main/astropy/visualization/__init__.py to fix this. Therefore, defining |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from contextlib import ExitStack, contextmanager | ||
|
|
||
| from astropy.visualization.time import time_support | ||
| from astropy.visualization.units import quantity_support | ||
|
|
||
|
|
||
| @contextmanager | ||
| def astropy_support(*, quantity_support_kwargs=None, time_support_kwargs=None): | ||
| """ | ||
| Enable support for plotting `astropy.units.Quantity` and `astropy.time.Time` instances in | ||
| matplotlib. | ||
|
|
||
| It can be used as a decorator or with a ``with`` statement. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, but I'd like the examples to be presented in the same order they are introduced in this sentence.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that makes sense. I've made the correction.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thinkg that moving code around is rarely worth the cost of making |
||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| .. plot:: | ||
| :include-source: | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import astropy.units as u | ||
| from astropy.time import Time | ||
| from astropy.visualization.astropy_support import astropy_support | ||
|
|
||
| @astropy_support() | ||
| def plot_example(): | ||
| plt.figure() | ||
| plt.plot([1, 2, 3] * u.m) | ||
| plt.plot(Time(['2000-01-01', '2000-01-02', '2000-01-03']).plot_date) | ||
| plt.draw() | ||
| plt.show() | ||
|
|
||
| with astropy_support(): # doctest: +IGNORE_OUTPUT | ||
| plt.figure() | ||
| plt.plot([1, 2, 3] * u.m) | ||
| plt.plot(Time(['2000-01-01', '2000-01-02', '2000-01-03']).plot_date) | ||
| plt.draw() | ||
|
|
||
| """ | ||
| with ExitStack() as stack: | ||
| stack.enter_context(quantity_support(**(quantity_support_kwargs or {}))) | ||
| stack.enter_context(time_support(**(time_support_kwargs or {}))) | ||
| yield | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Added a new ``astropy_support`` context manager in ``astropy.visualization``. | ||
| This enables ``time_support`` and ``quantity_support`` for plotting ``astropy.units.Quantity`` and ``astropy.time.Time`` instances in matplotlib. |
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.
For consistency with existing entries, I would still like this to be moved higher up (where other
astropy.visualization.wcsaxes.tests.test_imagesentries are), ordered alphabetically if possible.