Skip to content

Commit

Permalink
[Rendering] Import matplotplib only if necessary (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobettini authored May 20, 2024
1 parent 4f7ad73 commit a026a85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/unittest/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-cov tqdm matplotlib
python -m pip install flake8 pytest pytest-cov tqdm matplotlib==3.6
python -m pip install cvxpylayers # Navigation heuristic

pip install -e .
8 changes: 4 additions & 4 deletions vmas/simulator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

_has_matplotlib = importlib.util.find_spec("matplotlib") is not None

if _has_matplotlib:
from matplotlib import cm

X = 0
Y = 1
Z = 2
Expand Down Expand Up @@ -124,13 +121,16 @@ def x_to_rgb_colormap(
cmap_name: str = "viridis",
cmap_res: int = 10,
):
from matplotlib import cm

colormap = cm.get_cmap(cmap_name, cmap_res)(range(cmap_res))[:, :-1]
if low is None:
low = np.min(x)
if high is None:
high = np.max(x)
x = np.clip(x, low, high)
x = (x - low) / (high - low) * (cmap_res - 1)
if high - low > 1e-5:
x = (x - low) / (high - low) * (cmap_res - 1)
x_c0_idx = np.floor(x).astype(int)
x_c1_idx = np.ceil(x).astype(int)
x_c0 = colormap[x_c0_idx, :]
Expand Down

0 comments on commit a026a85

Please sign in to comment.