From 8b38f8c8ce01fef40f321500c39c51feb46f057a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Herrer=C3=ADas=20Azcu=C3=A9?= Date: Wed, 14 May 2025 13:22:47 +0100 Subject: [PATCH] quantity_support call in 06-units_and_quantities.md I'd not used the library before, but it seems you need a call to quantity_support(), either on its own or on a context manager --- episodes/06-units_and_quantities.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/episodes/06-units_and_quantities.md b/episodes/06-units_and_quantities.md index 7de6ffd..de8b48c 100644 --- a/episodes/06-units_and_quantities.md +++ b/episodes/06-units_and_quantities.md @@ -323,6 +323,7 @@ Support has been added for using the units information in matplotlib plots. To u ```python from astropy.visualization import quantity_support +quantity_support() # see note below ``` We will create a numpy array of the angles between 0-180 degrees, and plot the sin of these: @@ -344,6 +345,17 @@ plt.plot(angles.to(u.rad), np.sin(angles)) ![](fig/sin_curve_rad.png){alt='Plot of sin curve for degrees between 0-180'} +::::::::::::::::: callout +NOTE +The call to `quantity_support()` is required to "patch" `matplotlib` to recognize the `astropy.units`, and it will affect anything you plot from that point onward. +If you only need `quantity_support` for some plots, you can use a _context manager_: + +```python +with quantity_support(): + plt.plot(angles, np.sin(angles)) +``` +::::::::::::::::::::::::: + ## Temperature Each of the temperature scales is considered as using an irreducible unit in standard usage. As a consequence of this we need to always specify that we are using the `u.temperature` equivalences when we convert between these: