Skip to content

Commit

Permalink
Consistent hot/cold spot colors for local moran (#185)
Browse files Browse the repository at this point in the history
* (bug) support graph in moran's viz

* additional fixes for graph support in esda viz

* Revert "additional fixes for graph support in esda viz"

This reverts commit b2acf98.

* additional fixes for supporting graph in esda viz

* (bug) make sure cold/hot spot colors are consistent
  • Loading branch information
weikang9009 committed Aug 31, 2024
1 parent 7b6459b commit e4709f9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions splot/_viz_esda_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,8 @@ def _moran_loc_scatterplot(

# colors
spots = moran_hot_cold_spots(moran_loc, p)
hmap = colors.ListedColormap(
["#bababa", "#d7191c", "#abd9e9", "#2c7bb6", "#fdae61"]
)
color_all = numpy.array(["#bababa", "#d7191c", "#abd9e9", "#2c7bb6", "#fdae61"])
hmap = colors.ListedColormap(color_all[list(numpy.unique(spots))])

# define customization
scatter_kwds.setdefault("alpha", 0.6)
Expand All @@ -870,9 +869,10 @@ def _moran_loc_scatterplot(
if p is not None:
fitline_kwds.setdefault("color", "k")
scatter_kwds.setdefault("cmap", hmap)
scatter_kwds.setdefault("c", spots)
scatter_kwds.setdefault("c", numpy.sort(spots))
ax.plot(lag, fit.predy, **fitline_kwds)
ax.scatter(moran_loc.z, fit.predy, **scatter_kwds)
ax.scatter(moran_loc.z[spots.argsort()], fit.predy[spots.argsort()],
**scatter_kwds)
else:
scatter_kwds.setdefault("color", splot_colors["moran_base"])
fitline_kwds.setdefault("color", splot_colors["moran_fit"])
Expand All @@ -890,9 +890,10 @@ def _moran_loc_scatterplot(
if p is not None:
fitline_kwds.setdefault("color", "k")
scatter_kwds.setdefault("cmap", hmap)
scatter_kwds.setdefault("c", spots)
scatter_kwds.setdefault("c", numpy.sort(spots))
ax.plot(moran_loc.y, a + b * moran_loc.y, **fitline_kwds)
ax.scatter(moran_loc.y, lag, **scatter_kwds)
ax.scatter(moran_loc.y[spots.argsort()], lag[spots.argsort()],
**scatter_kwds)
else:
scatter_kwds.setdefault("c", splot_colors["moran_base"])
fitline_kwds.setdefault("color", splot_colors["moran_fit"])
Expand Down

0 comments on commit e4709f9

Please sign in to comment.