Open mhvk opened 5 months ago
It might be a good idea to highlight quantity_support()
, but what I suggested was even simpler:
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.24.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from astropy import units as u
In [2]: q = 5 * u.km / u.s
In [3]: f"{q:latex_inline}"
Out[3]: '$5 \\; \\mathrm{km\\,s^{-1}}$'
In [4]: f"{q.unit:unicode}"
Out[4]: 'km s⁻¹'
I have found this to be very useful in plot titles, legends and labels.
Suggestion by @eerovaher - it is really nice that one can make plots that automatically show the units on the labels (and convert different elements). Would be nice to include that in the notebook -- and possibly even in the slides! See https://docs.astropy.org/en/stable/visualization/matplotlib_integration.html