From be97f10d87ef59a6aba0bfa7cdb36cce08da8363 Mon Sep 17 00:00:00 2001
From: jgliss <jonasgliss@gmail.com>
Date: Sat, 18 May 2019 17:00:07 +0200
Subject: [PATCH] Removed global matplotlib imports in all modules (due to
 import failure on circleci for registration in conda-forge) and updated
 version to 1.4.3

---
 VERSION.rst        |  2 +-
 geonum/geosetup.py |  4 +-
 geonum/helpers.py  |  8 ++--
 geonum/mapping.py  | 94 +++++++++++-----------------------------------
 setup.py           |  1 -
 5 files changed, 27 insertions(+), 82 deletions(-)

diff --git a/VERSION.rst b/VERSION.rst
index 347f583..428b770 100644
--- a/VERSION.rst
+++ b/VERSION.rst
@@ -1 +1 @@
-1.4.1
+1.4.3
diff --git a/geonum/geosetup.py b/geonum/geosetup.py
index fd65f71..b4a0ab4 100644
--- a/geonum/geosetup.py
+++ b/geonum/geosetup.py
@@ -27,7 +27,6 @@
 from os.path import exists
 from traceback import print_exc
 from warnings import warn
-from matplotlib.pyplot import get_cmap, figure
 
 from geonum.geopoint import GeoPoint
 from geonum.geovector3d import GeoVector3D
@@ -82,7 +81,7 @@ def __init__(self, points=[], vectors=[], lat_ll=None, lon_ll=None,
         self.id = id
         self.points = {}
         self.vectors = {}
-        
+        from matplotlib.pyplot import get_cmap
         try:
             cmap = get_cmap(cmap_vecs)
         except:
@@ -514,6 +513,7 @@ def plot_2d(self, draw_all_points=True, draw_all_vectors=True,
                               "is not available")
         if not "ax" in kwargs:
             #fig, ax = subplots(1,1)
+            from matplotlib.pyplot import figure
             fig = figure(figsize=(10,8))
             ax = fig.add_axes([0.12,0.15,0.8,0.8])
             kwargs["ax"] = ax
diff --git a/geonum/helpers.py b/geonum/helpers.py
index 999c468..5f6d17e 100644
--- a/geonum/helpers.py
+++ b/geonum/helpers.py
@@ -21,9 +21,6 @@
 """
 import os
 import numpy as np
-import matplotlib.cm as colormaps
-import matplotlib.colors as colors
-from matplotlib.pyplot import draw
 
 exponent = lambda num: np.int(np.floor(np.log10(np.abs(num))))
 
@@ -72,11 +69,10 @@ def isnum(val):
 
 def rotate_xtick_labels(ax, deg=30, ha="right"):
     """Rotate xtick labels in matplotlib axes object"""
-    draw()
+    
     lbls = ax.get_xticklabels()
     lbls = [lbl.get_text() for lbl in lbls]
     ax.set_xticklabels(lbls, rotation = 30, ha = "right")
-    draw()
     return ax
     
 def haversine_formula(lon0, lat0, lon1, lat1, radius=6371.0):
@@ -142,6 +138,8 @@ def shifted_color_map(vmin, vmax, cmap=None):
         - shifted colormap
         
     """
+    import matplotlib.cm as colormaps
+    import matplotlib.colors as colors
     #midpoint = 1 - np.abs(im.max())/(np.abs(im.max()) + np.abs(im.min()))
     if cmap is None:
         cmap = colormaps.seismic
diff --git a/geonum/mapping.py b/geonum/mapping.py
index 71885db..2ee60f8 100644
--- a/geonum/mapping.py
+++ b/geonum/mapping.py
@@ -20,9 +20,6 @@
 except:
     print('Plotting of maps etc. is deactivated, please install Basemap')
 
-import matplotlib.pyplot as plt
-import matplotlib.cm as colormaps
-from mpl_toolkits import mplot3d
 import numpy as np    
 
 from geonum.topodataaccess import TopoDataAccess
@@ -231,6 +228,8 @@ def _convert_float(self, val):
     
     def _check_ax3d(self, ax):
         """Check if input is :class:`Axes3D`"""
+
+        from mpl_toolkits import mplot3d
         if isinstance(ax, mplot3d.Axes3D):
             return True
         return False
@@ -240,11 +239,10 @@ def set_ticks_topo_colorbar(self, start, stop, step):
         cb = self.colorbars["topo"]
         ticks = np.arange(start, stop, step)
         cb.set_ticks(ticks)
-        plt.draw()
         
     def draw_topo(self, insert_colorbar=False, include_seabed=True,
-                    max_grid_points=500, cmap_div=colormaps.coolwarm,
-                    cmap_seq=colormaps.Oranges, alpha=0.5, ax=None):
+                    max_grid_points=500, cmap_div=None,
+                    cmap_seq=None, alpha=0.5, ax=None):
         """Draw topography into map
         
         :param bool insert_colorbar: draws a colorbar for altitude
@@ -263,11 +261,18 @@ def draw_topo(self, insert_colorbar=False, include_seabed=True,
             topography
         :param ax: matplotlib axes object
         """
+        import matplotlib.cm as colormaps
+        if cmap_div is None:
+            cmap_div = colormaps.coolwarm
+        if cmap_seq is None:
+            cmap_seq = colormaps.Oranges
+        
         try:  
             if ax is None:
                 ax = self.ax
             if ax is None:
-                fig, ax = plt.subplots(1, 1, figsize=(16,10))
+                from matplotlib.pyplot import subplots
+                fig, ax = subplots(1, 1, figsize=(16,10))
                 self.ax = ax
     
             (x, y, z, z_min, z_max, 
@@ -309,69 +314,7 @@ def draw_topo(self, insert_colorbar=False, include_seabed=True,
                  "etopo() instead...")
             print(msg + repr(e))
             self.etopo()
-            
-    def draw_topo_old(self, insert_colorbar=False, include_seabed=True,
-                    max_grid_points=500, cmap_div=colormaps.coolwarm,
-                    cmap_seq=colormaps.Oranges, alpha=0.5, ax=None):
-        """Draw topography into map
-        
-        :param bool insert_colorbar: draws a colorbar for altitude
-            range (default: False)
-        :param bool include_seabed: include seabed topography 
-            (default: True)
-        :param int max_grid_points: resolution of displayed topo data 
-            points (makes it faster in interactive mode, default: 500)
-        :param str cmap_div: name of a diverging colormap (this one is 
-            used if :arg:`include_seabed` is True, and the cmap is shifted 
-            such , that white colors correspond to sea level altitude, 
-            default: "coolwarm")
-        :param str cmap_seq: name of a sequential colormap (this one is 
-            used if :arg:`include_seabed` is False, default: "Oranges")
-        :param float alpha: Alpha value (transparency) of plotted 
-            topography
-        :param ax: matplotlib axes object
-        """
-        try:  
-            if ax is None:
-                ax = self.ax
-            if ax is None:
-                fig, ax = plt.subplots(1, 1, figsize=(16,10))
-                self.ax = ax
-    
-            x, y, z, z_min, z_max, z_order =\
-                self._prep_topo_data(grid_points=max_grid_points)
-                
-            if z_min > 0:
-                include_seabed = 1
-                
-            z_step = (z_max - z_min) / 1000. 
-            
-            if include_seabed:
-                levels_filled = np.arange(z_min, z_max + z_step, z_step)
-            else:
-                levels_filled = np.arange(0, z_max + 1, z_step)
-            if levels_filled[0] < 0:          
-                shifted_cmap = shifted_color_map(z_min, z_max, cmap_div)
-                
-                cs2 = ax.contourf(x, y, z, levels_filled, cmap=shifted_cmap,
-                                  extend="both", alpha=alpha)
-                                  
-            elif levels_filled[0] >= 0:        
-                print("HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEERE")
-                cs2 = ax.contourf(x, y, z, levels_filled, cmap=cmap_seq,
-                                  alpha=1.0, extend="min")
-                self.contour_filled = cs2
-                    
-            if insert_colorbar:              
-                self.insert_colorbar("topo", cs2, label="Altitude [m]")
-        
-        except Exception as e:
-            raise
-            msg=("Could not draw topography in high res, using default "
-                 "etopo() instead...")
-            print(msg + repr(e))
-            self.etopo()
-         
+                 
     def draw_topo_3d(self, num_ticks=4, cmap="Oranges", alpha=0.5,
                      contour_color="#708090", contour_antialiased=True, 
                      contour_lw=0.2, ax=None, figsize=(16,8)):
@@ -401,7 +344,9 @@ def draw_topo_3d(self, num_ticks=4, cmap="Oranges", alpha=0.5,
             if self._check_ax3d(self.ax):
                 ax = self.ax
             else:
-                fig = plt.figure(figsize=figsize)
+                from mpl_toolkits import mplot3d
+                from matplotlib.pyplot import figure
+                fig = figure(figsize=figsize)
                 ax = mplot3d.Axes3D(fig)
     
         x, y, z, z_min, z_max, z_order = self._prep_topo_data()
@@ -673,7 +618,7 @@ def draw_geo_point_3d(self, p, ax=None, alt_offset_m=0.0, **kwargs):
             kwargs["marker"] = "^"
         if not any([x in kwargs for x in ["c", "color"]]):
             kwargs["c"] = "lime"
-
+        from mpl_toolkits import mplot3d
         if not isinstance(self.ax, mplot3d.Axes3D):
             raise ValueError("Need :class:`Axes3D` object as input...")
         x0, y0 = self(p.longitude, p.latitude)
@@ -695,6 +640,7 @@ def draw_geo_vector_3d(self, vec, ax=None,  **kwargs):
         if ax is None:
             ax = self.ax
         try:
+            from mpl_toolkits import mplot3d
             if not isinstance(ax, mplot3d.Axes3D):
                 raise ValueError("Need :class:`Axes3D` object as input...")
             elif not vec.type() == "GeoVector3D":
@@ -739,7 +685,8 @@ def add_polygon_2d(self, points=[], poly_id="undefined", ax=None, **kwargs):
                 coords.append(self(p.longitude, p.latitude))
             except Exception as e:
                 print("Failed to add one point to poly: " + repr(e))
-        polygon = plt.Polygon(coords, **kwargs)
+        from matplotlib.pyplot import Polygon
+        polygon = Polygon(coords, **kwargs)
         ax.add_patch(polygon)
         
     def add_polygon_3d(self, points=[], poly_id="undefined", ax=None, **kwargs):
@@ -749,6 +696,7 @@ def add_polygon_3d(self, points=[], poly_id="undefined", ax=None, **kwargs):
         :param str poly_id: string ID of this object (e.g. for 
             deletion, default: "undefined")
         """
+        from mpl_toolkits import mplot3d
         if ax is None:
             ax = self.ax
         if not "label" in kwargs:
diff --git a/setup.py b/setup.py
index c93bd20..a05d48e 100644
--- a/setup.py
+++ b/setup.py
@@ -50,7 +50,6 @@
         # that you indicate whether you support Python 2, Python 3 or both.,
         'Programming Language :: Python :: 2.7',
         'Programming Language :: Python :: 3'
-        'Programming Language :: Python :: 3.7'
     ],
     
     #dependency_links    =   ["https://github.com/tkrajina/srtm.py/archive/v.0.3.1.zip#egg=srtm"],