Skip to content

Commit

Permalink
ensure matplotlib is optional by removing plt colormap from input args
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklise committed Nov 18, 2023
1 parent ab4636e commit 86c7c1a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions chama/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
from matplotlib.collections import PatchCollection
from matplotlib.animation import FuncAnimation
except:
pass
plt = None

from scipy.spatial import ConvexHull
import numpy as np
from chama.sensors import Mobile


def signal_convexhull(signal, scenarios, threshold, timesteps=None,
colormap=plt.cm.viridis,
colormap=None,
x_range=(None, None), y_range=(None, None),
z_range=(None, None)):
"""
Expand All @@ -54,6 +54,11 @@ def signal_convexhull(signal, scenarios, threshold, timesteps=None,
z_range: tuple (optional)
The z-axis limits for the plot
"""
if plt is None:
raise ImportError('matplotlib is required for graphics')
if colormap is None:
colormap = plt.get_cmap('viridis')

t_col = 'T'
x_col = 'X'
y_col = 'Y'
Expand Down Expand Up @@ -104,7 +109,7 @@ def signal_convexhull(signal, scenarios, threshold, timesteps=None,

def signal_xsection(signal, signal_name, threshold=None, timesteps=None,
x_value=None, y_value=None, z_value=None, log_flag=False,
colormap=plt.cm.viridis, alpha=0.7, N=5,
colormap=None, alpha=0.7, N=5,
x_range=(None, None), y_range=(None, None),
z_range=(None, None)):
"""
Expand Down Expand Up @@ -147,7 +152,11 @@ def signal_xsection(signal, signal_name, threshold=None, timesteps=None,
z_range: tuple (optional)
The z-axis limits for the plot
"""

if plt is None:
raise ImportError('matplotlib is required for graphics')
if colormap is None:
colormap = plt.get_cmap('viridis')

t_col = 'T'
x_col = 'X'
y_col = 'Y'
Expand Down Expand Up @@ -318,7 +327,10 @@ def circles(x, y, s, c='b', vmin=None, vmax=None, **kwargs):
if c is not None:
plt.sci(collection)
return collection


if plt is None:
raise ImportError('matplotlib is required for graphics')

fig, ax = plt.subplots()
# ln, = plt.plot([],[],animated=True)

Expand Down Expand Up @@ -371,7 +383,9 @@ def sensor_locations(sensors, x_range=(None, None), y_range=(None, None),
sensor. The key:value pairs are {'sensor name' : String
representing the marker to be passed to the plot function)
"""

if plt is None:
raise ImportError('matplotlib is required for graphics')

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

Expand Down

0 comments on commit 86c7c1a

Please sign in to comment.