Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blit support and fix documentation #22

Merged
merged 5 commits into from
Jul 12, 2019
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
9 changes: 5 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ Here are parameters of the **ScaleBar** class constructor.
* ``dimension``: dimension of *dx* and *units*.
It can either be equal

* ``SI_LENGTH``: scale bar showing km, m, cm, etc.
* ``IMPERIAL_LENGTH``: scale bar showing in, ft, yd, mi, etc.
* ``SI_LENGTH_RECIPROCAL``: scale bar showing 1/m, 1/cm, etc.
* ``PIXEL_LENGTH``: scale bar showing px, kpx, Mpx, etc.
* ``si-length``: scale bar showing km, m, cm, etc.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this was confusing. SI_LENGTH actually refers to a module variable, which could have been imported along the ScaleBar class, but you are write I am sure most people uses the string.

* ``imperial-length``: scale bar showing in, ft, yd, mi, etc.
* ``si-length-reciprocal``: scale bar showing 1/m, 1/cm, etc.
* ``pixel-length``: scale bar showing px, kpx, Mpx, etc.
* a ``matplotlib_scalebar.dimension._Dimension`` object

* ``label``: optional label associated with the scale bar
Expand Down Expand Up @@ -135,6 +135,7 @@ Here are parameters of the **ScaleBar** class constructor.
automatically determined based on *length_fraction*.
* ``fixed_units``: units of the *fixed_value*. If ``None`` and
*fixed_value* is not ``None``, the units of *dx* are used.
* ``animated``: animation state (default: ``False``)

matplotlibrc parameters
-----------------------
Expand Down
19 changes: 12 additions & 7 deletions matplotlib_scalebar/scalebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""

__all__ = ['ScaleBar',
'SI_LENGTH', 'SI_LENGTH_RECIPROCAL', 'IMPERIAL_LENGTH']
'SI_LENGTH', 'SI_LENGTH_RECIPROCAL', 'IMPERIAL_LENGTH', 'PIXEL_LENGTH']

# Standard library modules.
import bisect
Expand Down Expand Up @@ -110,12 +110,13 @@ class ScaleBar(Artist):
'center': 10,
}

def __init__(self, dx, units='m', dimension=SI_LENGTH, label=None,
def __init__(self, dx, units='m', dimension='si-length', label=None,
length_fraction=None, height_fraction=None,
location=None, pad=None, border_pad=None, sep=None,
frameon=None, color=None, box_color=None, box_alpha=None,
scale_loc=None, label_loc=None, font_properties=None,
label_formatter=None, fixed_value=None, fixed_units=None):
label_formatter=None, fixed_value=None, fixed_units=None,
animated=False):
"""
Creates a new scale bar.

Expand All @@ -139,10 +140,10 @@ def __init__(self, dx, units='m', dimension=SI_LENGTH, label=None,

:arg dimension: dimension of *dx* and *units*.
It can either be equal
* ``: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:`PIXEL_LENGTH```: scale bar showing px, kpx, Mpx, etc.
* ``: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:`pixel-length```: scale bar showing px, kpx, Mpx, etc.
* a :class:`matplotlib_scalebar.dimension._Dimension` object
:type dimension: :class:`str` or
:class:`matplotlib_scalebar.dimension._Dimension`
Expand Down Expand Up @@ -218,6 +219,9 @@ def __init__(self, dx, units='m', dimension=SI_LENGTH, label=None,
:arg fixed_units: units of the *fixed_value*. If ``None`` and
*fixed_value* is not ``None``, the units of *dx* are used.
:type fixed_units: :class:`str`

:arg animated: animation state (default: ``False``)
:type animated: :class`bool`
"""
Artist.__init__(self)

Expand Down Expand Up @@ -251,6 +255,7 @@ def __init__(self, dx, units='m', dimension=SI_LENGTH, label=None,
self.font_properties = font_properties
self.fixed_value = fixed_value
self.fixed_units = fixed_units
self.set_animated(animated)

def _calculate_best_length(self, length_px):
dx = self.dx
Expand Down