From d87ced3dccd2bc45256ac3483c8848560de81766 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Sun, 21 Aug 2022 22:03:13 -0400 Subject: [PATCH 1/3] Add astronomical length units --- matplotlib_scalebar/dimension.py | 12 ++++++++++++ matplotlib_scalebar/scalebar.py | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/matplotlib_scalebar/dimension.py b/matplotlib_scalebar/dimension.py index e561b95..d272e74 100644 --- a/matplotlib_scalebar/dimension.py +++ b/matplotlib_scalebar/dimension.py @@ -136,6 +136,18 @@ def __init__(self): self.add_units("lea", 15840) +class AstronomicalLengthDimension(_Dimension): + def __init__(self): + super.__init__("pc") + for prefix, factor in _PREFIXES_FACTORS.items(): + latexrepr = None + if prefix == "\u00b5" or prefix == "u": + latexrepr = _LATEX_MU + "kpc" + self.add_units(prefix + "m", factor, latexrepr) + self.add_units("ly", 0.30659485) + self.add_units("AU", 4.84813681e-06) + + class PixelLengthDimension(_Dimension): def __init__(self): super().__init__("px") diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index 92382b1..1164aac 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -33,6 +33,7 @@ "SI_LENGTH", "SI_LENGTH_RECIPROCAL", "IMPERIAL_LENGTH", + "ASTRO_LENGTH", "PIXEL_LENGTH", ] @@ -66,6 +67,7 @@ SILengthDimension, SILengthReciprocalDimension, ImperialLengthDimension, + AstronomicalLengthDimension, PixelLengthDimension, AngleDimension, ) @@ -126,6 +128,7 @@ def _validate_legend_loc(loc): SI_LENGTH = "si-length" SI_LENGTH_RECIPROCAL = "si-length-reciprocal" IMPERIAL_LENGTH = "imperial-length" +ASTRO_LENGTH = "astro-length" PIXEL_LENGTH = "pixel-length" ANGLE = "angle" @@ -133,6 +136,7 @@ def _validate_legend_loc(loc): SI_LENGTH: SILengthDimension, SI_LENGTH_RECIPROCAL: SILengthReciprocalDimension, IMPERIAL_LENGTH: ImperialLengthDimension, + ASTRO_LENGTH: AstronomicalLengthDimension, PIXEL_LENGTH: PixelLengthDimension, ANGLE: AngleDimension, } @@ -212,6 +216,7 @@ def __init__( * ``:const:`si-length```: scale bar showing km, m, cm, etc. * ``:const:`imperial-length```: scale bar showing in, ft, yd, mi, etc. * ``:const:`si-length-reciprocal```: scale bar showing 1/m, 1/cm, etc. + * ``:const:`astro-length```: scale bar showing pc, kpc, Mpc, ly, AU, etc. * ``:const:`pixel-length```: scale bar showing px, kpx, Mpx, etc. * ``:const:`angle```: scale bar showing \u00b0, \u2032 or \u2032\u2032. * a :class:`matplotlib_scalebar.dimension._Dimension` object From c1ea7e2210fa502cb106a16fa61c51c11240aa9b Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Sun, 21 Aug 2022 22:07:25 -0400 Subject: [PATCH 2/3] add astro-length to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3d2389d..ccbede1 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ Dimension of *dx* and *units*. It can either be equal: * `si-length` (default): scale bar showing km, m, cm, etc. * `imperial-length`: scale bar showing in, ft, yd, mi, etc. +* `astro-length`: scale bar showing pc, kpc, Mpc, ly, AU, etc. * `si-length-reciprocal`: scale bar showing 1/m, 1/cm, etc. * `pixel-length`: scale bar showing px, kpx, Mpx, etc. * `angle`: scale bar showing °, ʹ (minute of arc) or ʹʹ (second of arc) From c3fb442cbbe6eb2ca006b184fb67787e7d0fc2de Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Mon, 22 Aug 2022 09:11:06 -0400 Subject: [PATCH 3/3] Fix bugs --- matplotlib_scalebar/dimension.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matplotlib_scalebar/dimension.py b/matplotlib_scalebar/dimension.py index d272e74..5792a34 100644 --- a/matplotlib_scalebar/dimension.py +++ b/matplotlib_scalebar/dimension.py @@ -138,12 +138,12 @@ def __init__(self): class AstronomicalLengthDimension(_Dimension): def __init__(self): - super.__init__("pc") + super().__init__("pc") for prefix, factor in _PREFIXES_FACTORS.items(): latexrepr = None if prefix == "\u00b5" or prefix == "u": - latexrepr = _LATEX_MU + "kpc" - self.add_units(prefix + "m", factor, latexrepr) + latexrepr = _LATEX_MU + "pc" + self.add_units(prefix + "pc", factor, latexrepr) self.add_units("ly", 0.30659485) self.add_units("AU", 4.84813681e-06)