Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions matplotlib_scalebar/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "pc"
self.add_units(prefix + "pc", factor, latexrepr)
self.add_units("ly", 0.30659485)
self.add_units("AU", 4.84813681e-06)


class PixelLengthDimension(_Dimension):
def __init__(self):
super().__init__("px")
Expand Down
5 changes: 5 additions & 0 deletions matplotlib_scalebar/scalebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"SI_LENGTH",
"SI_LENGTH_RECIPROCAL",
"IMPERIAL_LENGTH",
"ASTRO_LENGTH",
"PIXEL_LENGTH",
]

Expand Down Expand Up @@ -66,6 +67,7 @@
SILengthDimension,
SILengthReciprocalDimension,
ImperialLengthDimension,
AstronomicalLengthDimension,
PixelLengthDimension,
AngleDimension,
)
Expand Down Expand Up @@ -126,13 +128,15 @@ 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"

_DIMENSION_LOOKUP = {
SI_LENGTH: SILengthDimension,
SI_LENGTH_RECIPROCAL: SILengthReciprocalDimension,
IMPERIAL_LENGTH: ImperialLengthDimension,
ASTRO_LENGTH: AstronomicalLengthDimension,
PIXEL_LENGTH: PixelLengthDimension,
ANGLE: AngleDimension,
}
Expand Down Expand Up @@ -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
Expand Down