From 3c07f59a88df3348294155b166cccc2e526e45d7 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Tue, 11 Jun 2019 18:11:44 +0100 Subject: [PATCH 1/5] Add support for blitting. --- matplotlib_scalebar/scalebar.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index 58ce0c5..c6ac89c 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -115,7 +115,8 @@ def __init__(self, dx, units='m', dimension=SI_LENGTH, label=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, + use_blit=False): """ Creates a new scale bar. @@ -251,6 +252,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.use_blit = use_blit def _calculate_best_length(self, length_px): dx = self.dx @@ -379,6 +381,7 @@ def _get_value(attr, default): box.patch.set_color(box_color) box.patch.set_alpha(box_alpha) box.draw(renderer) + self.set_animated(self.use_blit) def get_dx(self): return self._dx From bd5e124cfb52904d81c92df72360cac04a15102f Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Tue, 11 Jun 2019 18:16:09 +0100 Subject: [PATCH 2/5] Fix documentation dimension. --- README.rst | 9 ++++----- matplotlib_scalebar/scalebar.py | 11 +++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index e796811..00af551 100644 --- a/README.rst +++ b/README.rst @@ -94,11 +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. - * a ``matplotlib_scalebar.dimension._Dimension`` object + * ``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. * ``label``: optional label associated with the scale bar (default: ``None``, no label is shown) diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index c6ac89c..8980bde 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -110,7 +110,7 @@ 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, @@ -140,11 +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. - * a :class:`matplotlib_scalebar.dimension._Dimension` object + * ``: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. :type dimension: :class:`str` or :class:`matplotlib_scalebar.dimension._Dimension` From 094c1c687d86c892739c9ac866f8979dc8634251 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 7 Jul 2019 18:52:37 +0100 Subject: [PATCH 3/5] Rename `use_blit` to `animated`. --- matplotlib_scalebar/scalebar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index 8980bde..70788bb 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -116,7 +116,7 @@ def __init__(self, dx, units='m', dimension='si-length', label=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, - use_blit=False): + animated=False): """ Creates a new scale bar. @@ -251,7 +251,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.use_blit = use_blit + self.animated = animated def _calculate_best_length(self, length_px): dx = self.dx @@ -380,7 +380,7 @@ def _get_value(attr, default): box.patch.set_color(box_color) box.patch.set_alpha(box_alpha) box.draw(renderer) - self.set_animated(self.use_blit) + self.set_animated(self.animated) def get_dx(self): return self._dx From cd38808707c2c6def199d3a933225a1c8cb837c2 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 7 Jul 2019 19:06:10 +0100 Subject: [PATCH 4/5] Move `set_animated` to constructor. --- matplotlib_scalebar/scalebar.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index 70788bb..ffc5663 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -251,7 +251,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.animated = animated + self.set_animated(animated) def _calculate_best_length(self, length_px): dx = self.dx @@ -380,7 +380,6 @@ def _get_value(attr, default): box.patch.set_color(box_color) box.patch.set_alpha(box_alpha) box.draw(renderer) - self.set_animated(self.animated) def get_dx(self): return self._dx From 3ad3e010d03e4866a4399d99b244f53e64608bf6 Mon Sep 17 00:00:00 2001 From: Philippe Pinard Date: Fri, 12 Jul 2019 18:57:25 +0100 Subject: [PATCH 5/5] Fix documentation. Add doc for animated argument. --- README.rst | 2 ++ matplotlib_scalebar/scalebar.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 00af551..ba09288 100644 --- a/README.rst +++ b/README.rst @@ -98,6 +98,7 @@ Here are parameters of the **ScaleBar** class constructor. * ``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 (default: ``None``, no label is shown) @@ -134,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 ----------------------- diff --git a/matplotlib_scalebar/scalebar.py b/matplotlib_scalebar/scalebar.py index ffc5663..d59b326 100644 --- a/matplotlib_scalebar/scalebar.py +++ b/matplotlib_scalebar/scalebar.py @@ -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 @@ -144,6 +144,7 @@ def __init__(self, dx, units='m', dimension='si-length', label=None, * ``: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` @@ -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)