Skip to content

Commit

Permalink
Improved add colorbar function
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Apr 29, 2021
1 parent 4869f91 commit dc7e548
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions geemap/geemap.py
Expand Up @@ -2569,7 +2569,7 @@ def add_legend(

def add_colorbar(
self,
vis_params,
vis_params=None,
cmap="gray",
discrete=False,
label=None,
Expand Down Expand Up @@ -2603,6 +2603,26 @@ def add_colorbar(
import matplotlib.pyplot as plt
import numpy as np

if isinstance(vis_params, list):
vis_params = {"palette": vis_params}
elif vis_params is None:
vis_params = {}

if "colors" in kwargs and isinstance(kwargs["colors"], list):
vis_params["palette"] = kwargs["colors"]

if "vmin" in kwargs:
vis_params["min"] = kwargs["vmin"]
del kwargs["vmin"]

if "vmax" in kwargs:
vis_params["max"] = kwargs["vmax"]
del kwargs["vmax"]

if "caption" in kwargs:
label = kwargs["caption"]
del kwargs["caption"]

if not isinstance(vis_params, dict):
raise TypeError("The vis_params must be a dictionary.")

Expand Down Expand Up @@ -5062,4 +5082,4 @@ def linked_maps(
display(m)
grid[i, j] = output

return grid
return grid

0 comments on commit dc7e548

Please sign in to comment.