From f8b86653605ed475556ab4b5a17c82b61f0d377b Mon Sep 17 00:00:00 2001 From: mvlier <109704873+mvlier@users.noreply.github.com> Date: Sat, 27 Jul 2024 08:50:31 +0900 Subject: [PATCH 1/4] Fixed normalization Now the variable normalize gets the value False when the user specifies vmin and vmax. vmin and vmax can be defined when using mp.plot(..., shading = {"normalize" = [vmin, vmax]}, ...) If nothing is set by the user the standard value is "normalize" = [None, None]. If any of the two entries are None, then the variable normalize in Viewer.py gets the value True, and vmin and vmax are chosen inside utils.py in get_colors. --- meshplot/Viewer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/meshplot/Viewer.py b/meshplot/Viewer.py index d9ab8ae..aacce97 100644 --- a/meshplot/Viewer.py +++ b/meshplot/Viewer.py @@ -131,7 +131,7 @@ def __get_colors(self, v, f, c, sh): colors[:, 1] = 0.874 colors[:, 2] = 0.0 elif type(c) == np.ndarray and c.size == f.shape[0]: # Function values for faces - normalize = sh["normalize"][0] != None and sh["normalize"][1] != None + normalize = sh["normalize"][0] == None or sh["normalize"][1] == None cc = get_colors(c, sh["colormap"], normalize=normalize, vmin=sh["normalize"][0], vmax=sh["normalize"][1]) #print(cc.shape) @@ -139,7 +139,7 @@ def __get_colors(self, v, f, c, sh): coloring = "FaceColors" #print("Face function values") elif type(c) == np.ndarray and c.size == v.shape[0]: # Function values for vertices - normalize = sh["normalize"][0] != None and sh["normalize"][1] != None + normalize = sh["normalize"][0] == None or sh["normalize"][1] == None colors = get_colors(c, sh["colormap"], normalize=normalize, vmin=sh["normalize"][0], vmax=sh["normalize"][1]) #print("Vertex function values") @@ -167,7 +167,7 @@ def __get_point_colors(self, v, c, sh): elif type(c) == np.ndarray and len(c.shape) == 2 and c.shape[1] == 3 and c.shape[0] == v.shape[0]: # Point color colors = c.astype("float32", copy=False) elif type(c) == np.ndarray and c.size == v.shape[0]: # Function color - normalize = sh["normalize"][0] != None and sh["normalize"][1] != None + normalize = sh["normalize"][0] == None or sh["normalize"][1] == None colors = get_colors(c, sh["colormap"], normalize=normalize, vmin=sh["normalize"][0], vmax=sh["normalize"][1]) colors = colors.astype("float32", copy=False) From 62a198e2c7355381bcd86800beff9e14f09c1b35 Mon Sep 17 00:00:00 2001 From: mvlier <109704873+mvlier@users.noreply.github.com> Date: Sat, 27 Jul 2024 09:40:31 +0900 Subject: [PATCH 2/4] Changed condition for normalize We don't need the variable normalize, since the condtion in get_colors can be written based on vmin and vmax --- meshplot/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meshplot/utils.py b/meshplot/utils.py index 91867f2..03682e6 100644 --- a/meshplot/utils.py +++ b/meshplot/utils.py @@ -3,9 +3,9 @@ import matplotlib as mpl # Helper functions -def get_colors(inp, colormap="viridis", normalize=True, vmin=None, vmax=None): +def get_colors(inp, colormap="viridis", vmin=None, vmax=None): colormap = plt.cm.get_cmap(colormap) - if normalize: + if vmin==None or vmax==None: vmin=np.min(inp) vmax=np.max(inp) From 1ab564ecffcf72c2cc2a0623386d7fd692bcba06 Mon Sep 17 00:00:00 2001 From: mvlier <109704873+mvlier@users.noreply.github.com> Date: Sat, 27 Jul 2024 09:44:13 +0900 Subject: [PATCH 3/4] Update Viewer.py in accordance with the new get_colors --- meshplot/Viewer.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/meshplot/Viewer.py b/meshplot/Viewer.py index aacce97..c409133 100644 --- a/meshplot/Viewer.py +++ b/meshplot/Viewer.py @@ -131,18 +131,14 @@ def __get_colors(self, v, f, c, sh): colors[:, 1] = 0.874 colors[:, 2] = 0.0 elif type(c) == np.ndarray and c.size == f.shape[0]: # Function values for faces - normalize = sh["normalize"][0] == None or sh["normalize"][1] == None - cc = get_colors(c, sh["colormap"], normalize=normalize, - vmin=sh["normalize"][0], vmax=sh["normalize"][1]) + cc = get_colors(c, sh["colormap"], vmin=sh["normalize"][0], vmax=sh["normalize"][1]) #print(cc.shape) colors = np.hstack([cc, cc, cc]).reshape((-1, 3)) coloring = "FaceColors" - #print("Face function values") + print("Face function values") elif type(c) == np.ndarray and c.size == v.shape[0]: # Function values for vertices - normalize = sh["normalize"][0] == None or sh["normalize"][1] == None - colors = get_colors(c, sh["colormap"], normalize=normalize, - vmin=sh["normalize"][0], vmax=sh["normalize"][1]) - #print("Vertex function values") + colors = get_colors(c, sh["colormap"], vmin=sh["normalize"][0], vmax=sh["normalize"][1]) + print("Vertex function values") else: colors = np.ones_like(v) colors[:, 0] = 1.0 From 92b33f8c84c9cce76773cfff90e4cc4cffd556b4 Mon Sep 17 00:00:00 2001 From: mvlier <109704873+mvlier@users.noreply.github.com> Date: Sat, 27 Jul 2024 09:53:18 +0900 Subject: [PATCH 4/4] Fixed get_colors call in Viewer.py --- meshplot/Viewer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/meshplot/Viewer.py b/meshplot/Viewer.py index c409133..82e8942 100644 --- a/meshplot/Viewer.py +++ b/meshplot/Viewer.py @@ -163,9 +163,7 @@ def __get_point_colors(self, v, c, sh): elif type(c) == np.ndarray and len(c.shape) == 2 and c.shape[1] == 3 and c.shape[0] == v.shape[0]: # Point color colors = c.astype("float32", copy=False) elif type(c) == np.ndarray and c.size == v.shape[0]: # Function color - normalize = sh["normalize"][0] == None or sh["normalize"][1] == None - colors = get_colors(c, sh["colormap"], normalize=normalize, - vmin=sh["normalize"][0], vmax=sh["normalize"][1]) + colors = get_colors(c, sh["colormap"], vmin=sh["normalize"][0], vmax=sh["normalize"][1]) colors = colors.astype("float32", copy=False) #print("Vertex function values") else: