Skip to content

Commit 0df0fe1

Browse files
committed
markdown source builds
Auto-generated via `{sandpaper}` Source : 8ed39d8 Branch : main Author : S Jaffa <SJaffa@users.noreply.github.com> Time : 2025-11-17 13:56:53 +0000 Message : Merge pull request #44 from UoMResearchIT/quantity_support_in_units_and_quantities quantity_support call in 06-units_and_quantities.md
1 parent 1af63eb commit 0df0fe1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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:

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"episodes/03-numpy_essential.md" "8be0e5afb556d4f597f31f059488dd15" "site/built/03-numpy_essential.md" "2025-04-15"
1010
"episodes/04-software_package_management.md" "62db2ba2a4291e16d2bdd07b77bfc961" "site/built/04-software_package_management.md" "2025-04-15"
1111
"episodes/05-defensive_programming.md" "357bca7361e09066ad71393e21ad0c74" "site/built/05-defensive_programming.md" "2025-04-15"
12-
"episodes/06-units_and_quantities.md" "f02e82346d2f3b9675c133921f1f922f" "site/built/06-units_and_quantities.md" "2025-04-15"
12+
"episodes/06-units_and_quantities.md" "aa0215a27f41d8c99db495c727c56051" "site/built/06-units_and_quantities.md" "2025-11-17"
1313
"episodes/07-pandas_essential.md" "5dde09b1125f8c30156ae314b5fdcfe1" "site/built/07-pandas_essential.md" "2025-04-15"
1414
"instructors/instructor-notes.md" "a59fd3b94c07c3fe3218c054a0f03277" "site/built/instructor-notes.md" "2025-04-15"
1515
"learners/discuss.md" "2758e2e5abd231d82d25c6453d8abbc6" "site/built/discuss.md" "2025-04-15"

0 commit comments

Comments
 (0)