Skip to content

Commit 8ed39d8

Browse files
authored
Merge pull request #44 from UoMResearchIT/quantity_support_in_units_and_quantities
quantity_support call in 06-units_and_quantities.md
2 parents be68a01 + 8b38f8c commit 8ed39d8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

episodes/06-units_and_quantities.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ Support has been added for using the units information in matplotlib plots. To u
323323

324324
```python
325325
from astropy.visualization import quantity_support
326+
quantity_support() # see note below
326327
```
327328

328329
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))
344345

345346
![](fig/sin_curve_rad.png){alt='Plot of sin curve for degrees between 0-180'}
346347

348+
::::::::::::::::: callout
349+
NOTE
350+
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.
351+
If you only need `quantity_support` for some plots, you can use a _context manager_:
352+
353+
```python
354+
with quantity_support():
355+
plt.plot(angles, np.sin(angles))
356+
```
357+
:::::::::::::::::::::::::
358+
347359
## Temperature
348360

349361
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:

0 commit comments

Comments
 (0)