Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGES.rst

Copy link
Copy Markdown
Contributor

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.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ astropy.table
default behavior will be to use the remote versions of jQuery and DataTables
from a CDN. [#17480]



Bug Fixes
---------

Expand Down Expand Up @@ -92,8 +94,8 @@ astropy.units
``.dtype``, independent of whether that is a numpy data type. [#17469]

- The zebi (Zi, 2^70) and yobi (Yi, 2^80) binary prefixes are now supported. [#17692]

astropy.visualization
**Added**
- Added `unit_support()` to enable both quantity and time support together. [#8860]
^^^^^^^^^^^^^^^^^^^^^

- Fix ``CoordinateHelper.ticklabels``. The getter was incorrectly returning
Expand Down Expand Up @@ -245,7 +247,7 @@ astropy.units
- Added support for calling numpy array constructors (``np.require``,
``np.identity``, ``np.eye``, ``np.tri``, ``np.genfromtxt`` and ``np.loadtxt``)
with ``like=Quantity(...))`` . [#17130]

Added `unit_support()` to enable both quantity and time support together. [#8860]
astropy.utils
^^^^^^^^^^^^^

Expand Down Expand Up @@ -18353,6 +18355,8 @@ astropy.wcs

- Minor VOTable fixes [#596]



- Fixed how ``setup.py`` uses ``distribute_setup.py`` to prevent possible
``VersionConflict`` errors when an older version of distribute is already
installed on the user's system. [#616, #640]
Expand Down
37 changes: 33 additions & 4 deletions astropy/visualization/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

__all__ = ["quantity_support"]
__all__ = ["quantity_support", "unit_support"] # ✅ أضفنا unit_support هنا

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
__all__ = ["quantity_support", "unit_support"] # ✅ أضفنا unit_support هنا
__all__ = [
"quantity_support",
"unit_support",
]

__doctest_skip__ = ["quantity_support"]


Expand All @@ -21,17 +21,16 @@
>>> with visualization.quantity_support():
... plt.figure()
... plt.plot([1, 2, 3] * u.m)
[...]
...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this line

... plt.plot([101, 125, 150] * u.cm)
[...]
...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
This is a convenience function that enables both astropy's
This is a convenience function that enables both

`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

Check warning on line 124 in astropy/visualization/units.py

View check run for this annotation

Codecov / codecov/patch

astropy/visualization/units.py#L124

Added line #L124 was not covered by tests

from astropy.visualization import quantity_support, time_support

Check warning on line 126 in astropy/visualization/units.py

View check run for this annotation

Codecov / codecov/patch

astropy/visualization/units.py#L126

Added line #L126 was not covered by tests

stack = ExitStack()
stack.enter_context(quantity_support(format=format))
stack.enter_context(time_support())
return stack

Check warning on line 131 in astropy/visualization/units.py

View check run for this annotation

Codecov / codecov/patch

astropy/visualization/units.py#L128-L131

Added lines #L128 - L131 were not covered by tests
1 change: 1 addition & 0 deletions docs/changelog.rst

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Expand Up @@ -8,3 +8,4 @@ Full Changelog
:towncrier: ../
:towncrier-skip-if-empty:
:changelog_file: ../CHANGES.rst
- Added `unit_support()` to enable both quantity and time support together. [#8860]
7 changes: 7 additions & 0 deletions docs/visualization/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed: ref_api will automatically generate the text we want to include here