diff --git a/kwant/plotter.py b/kwant/plotter.py index 5937fb3a21e9e2000b1e55c14aad65dd355ab847..0f5a11ea8ffbe8360fa3fea6ccef99625c5ae655 100644 --- a/kwant/plotter.py +++ b/kwant/plotter.py @@ -42,18 +42,30 @@ except ImportError: "functions will work.", RuntimeWarning) mpl_enabled = False -if mpl_enabled and matplotlib.__version__ == "1.4.0": - warnings.warn("matplotlib 1.4.0 has a bug that makes 3D plotting unusable " - "(2D plotting is not affected). Please consider using a " - "different version of matplotlib.", RuntimeWarning) - - from . import system, builder, physics __all__ = ['plot', 'map', 'bands', 'sys_leads_sites', 'sys_leads_hoppings', 'sys_leads_pos', 'sys_leads_hopping_pos', 'mask_interpolate'] +# TODO: Remove the following once we depend on matplotlib >= 1.4.1. +def matplotlib_chores(): + global pre_1_4_matplotlib + ver = matplotlib.__version__ + + if ver == "1.4.0": + warnings.warn("Matplotlib 1.4.0 has a bug that makes 3D plotting " + "unusable (2D plotting is not affected). Please " + "consider using a different version of matplotlib.", + RuntimeWarning) + + pre_1_4_matplotlib = [int(x) for x in ver.split('.')[:2]] < [1, 4] + + +if mpl_enabled: + matplotlib_chores() + + # Collections that allow for symbols and linewiths to be given in data space # (not for general use, only implement what's needed for plotter) def isarray(var): @@ -97,9 +109,13 @@ if mpl_enabled: self.reflen = reflen self._linewidths_orig = nparray_if_array(self.get_linewidths()) - self._transforms = np.array([ - matplotlib.transforms.Affine2D().scale(x).get_matrix() for x - in sizes]) + if pre_1_4_matplotlib: + self._transforms = [matplotlib.transforms.Affine2D().scale(x) + for x in sizes] + else: + self._transforms = np.array( + [matplotlib.transforms.Affine2D().scale(x).get_matrix() + for x in sizes]) def get_transforms(self): return self._transforms @@ -220,8 +236,12 @@ if mpl_enabled: self._edgecolors_orig = nparray_if_array(self.get_edgecolors()) Affine2D = matplotlib.transforms.Affine2D - self._orig_transforms = np.array([ - Affine2D().scale(x).get_matrix() for x in sizes]) + if pre_1_4_matplotlib: + self._orig_transforms = np.array( + [Affine2D().scale(x) for x in sizes], dtype='object') + else: + self._orig_transforms = np.array( + [Affine2D().scale(x).get_matrix() for x in sizes]) self._transforms = self._orig_transforms def set_array(self, array):