Skip to content

Commit

Permalink
Removed global matplotlib imports in all modules (due to import failu…
Browse files Browse the repository at this point in the history
…re on circleci for registration in conda-forge) and updated version to 1.4.3
  • Loading branch information
jgliss committed May 18, 2019
1 parent 107f42b commit be97f10
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 82 deletions.
2 changes: 1 addition & 1 deletion VERSION.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.1
1.4.3
4 changes: 2 additions & 2 deletions geonum/geosetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions geonum/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
94 changes: 21 additions & 73 deletions geonum/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit be97f10

Please sign in to comment.