From 2c5550601b18849a6efcdc5f32d18577b7852634 Mon Sep 17 00:00:00 2001 From: jameswillis Date: Fri, 2 Aug 2024 14:30:28 -0700 Subject: [PATCH] make matplotlib optional --- README.md | 1 + esda/moran.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99837b95..98d80e17 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ $ pip install git+https://github.com/pysal/esda@main - `numba>=0.57` - used to accelerate computational geometry and permutation-based statistical inference. - `rtree>=1.0` - required for `esda.topo.isolation()` +- `matplotlib` - required for `esda.moran.explore()` ## Contribute diff --git a/esda/moran.py b/esda/moran.py index 79a32c6b..64090c5d 100644 --- a/esda/moran.py +++ b/esda/moran.py @@ -16,7 +16,6 @@ import scipy.stats as stats from libpysal.weights import W from libpysal.weights.spatial_lag import lag_spatial -from matplotlib import colors from scipy import sparse from .crand import _prepare_univariate @@ -1786,6 +1785,11 @@ def _explore_local_moran(moran_local, gdf, crit_value, **kwargs): folium.Map """ + try: + from matplotlib import colors + except ImportError: + raise ImportError("matplotlib library must be installed to use the explore feature") from None + gdf = gdf.copy() gdf["Moran Cluster"] = moran_local.get_cluster_labels(crit_value) gdf["p-value"] = moran_local.p_sim