-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add unit_support() to enable quantity and time support together #17979
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
72dadca
1802c67
3c27769
5da5041
6fefedb
e4d0027
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||||||||
|
|
||||||||||||
| import numpy as np | ||||||||||||
|
|
||||||||||||
| __all__ = ["quantity_support"] | ||||||||||||
| __all__ = ["quantity_support", "unit_support"] # ✅ أضفنا unit_support هنا | ||||||||||||
|
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. We only allow comments in english, so most contributors can understand them
Suggested change
|
||||||||||||
| __doctest_skip__ = ["quantity_support"] | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -21,17 +21,16 @@ | |||||||||||
| >>> with visualization.quantity_support(): | ||||||||||||
| ... plt.figure() | ||||||||||||
| ... plt.plot([1, 2, 3] * u.m) | ||||||||||||
| [...] | ||||||||||||
| ... | ||||||||||||
|
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. please revert this line |
||||||||||||
| ... plt.plot([101, 125, 150] * u.cm) | ||||||||||||
| [...] | ||||||||||||
| ... | ||||||||||||
|
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. this one too |
||||||||||||
| ... plt.draw() | ||||||||||||
|
|
||||||||||||
| Parameters | ||||||||||||
| ---------- | ||||||||||||
| format : `astropy.units.format.Base` subclass or str | ||||||||||||
| The name of a format or a formatter class. If not | ||||||||||||
| provided, defaults to ``latex_inline``. | ||||||||||||
|
|
||||||||||||
| """ | ||||||||||||
| from matplotlib import ticker, units | ||||||||||||
|
|
||||||||||||
|
|
@@ -100,3 +99,33 @@ | |||||||||||
| units.registry[u.Quantity] = self._original_converter[u.Quantity] | ||||||||||||
|
|
||||||||||||
| return MplQuantityConverter() | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| # Add the unit_support function to the module's __all__ list | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def unit_support(format="latex_inline"): | ||||||||||||
| """ | ||||||||||||
| Enable both quantity and time support for matplotlib. | ||||||||||||
|
|
||||||||||||
| This is a convenience function that enables both astropy's | ||||||||||||
|
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 don't recall seeing that style in our docs, let's avoid it
Suggested change
|
||||||||||||
| `quantity_support` and `time_support`. | ||||||||||||
|
|
||||||||||||
| Parameters | ||||||||||||
| ---------- | ||||||||||||
| format : str | ||||||||||||
| Format for unit labels (default: 'latex_inline'). | ||||||||||||
|
|
||||||||||||
| Returns | ||||||||||||
| ------- | ||||||||||||
| context : contextlib.ExitStack | ||||||||||||
| A context manager that enables both supports. | ||||||||||||
| """ | ||||||||||||
| from contextlib import ExitStack | ||||||||||||
|
|
||||||||||||
| from astropy.visualization import quantity_support, time_support | ||||||||||||
|
|
||||||||||||
| stack = ExitStack() | ||||||||||||
| stack.enter_context(quantity_support(format=format)) | ||||||||||||
| stack.enter_context(time_support()) | ||||||||||||
| return stack | ||||||||||||
|
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. this file also shouldn't be updated in this PR |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,3 +48,10 @@ Reference/API | |
| :maxdepth: 2 | ||
|
|
||
| ref_api | ||
|
|
||
| .. function:: unit_support(format="latex_inline") | ||
|
|
||
| Enable both quantity and time support for matplotlib. | ||
|
|
||
| :param format: Format for unit labels (default: 'latex_inline'). | ||
| :returns: Context manager enabling both supports. | ||
|
Comment on lines
+52
to
+57
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 don't think this is needed: |
||
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.
We do not edit this file directly in PRs. Instead, please add a note as a new file, as described in
docs/changes/README.rst.