From 48d1bed84a3cfe38a3b732b483c48f24280e55c1 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Thu, 23 Jan 2025 09:20:45 +0100 Subject: [PATCH 1/4] Update mpl_space_drawing.py --- mesa/visualization/mpl_space_drawing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index b0e10d039ae..e74ac22269b 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -192,8 +192,9 @@ def draw_property_layers( data = layer.data.astype(float) if layer.data.dtype == bool else layer.data width, height = data.shape # if space is None else (space.width, space.height) + data = data.T - if space and data.shape != (width, height): + if space.dimensions != (width, height): warnings.warn( f"Layer {layer_name} dimensions ({data.shape}) do not match space dimensions ({width}, {height}).", UserWarning, From 4a17ece244b06e01d98971bd2f4321e4b5833b0f Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Thu, 23 Jan 2025 09:29:02 +0100 Subject: [PATCH 2/4] Update mpl_space_drawing.py --- mesa/visualization/mpl_space_drawing.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index e74ac22269b..9b86ea98311 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -191,10 +191,8 @@ def draw_property_layers( continue data = layer.data.astype(float) if layer.data.dtype == bool else layer.data - width, height = data.shape # if space is None else (space.width, space.height) - data = data.T - if space.dimensions != (width, height): + if space.dimensions != data.shape: warnings.warn( f"Layer {layer_name} dimensions ({data.shape}) do not match space dimensions ({width}, {height}).", UserWarning, @@ -218,7 +216,7 @@ def draw_property_layers( layer_name, [(0, 0, 0, 0), (*rgba_color[:3], alpha)] ) im = ax.imshow( - rgba_data, + rgba_data.T, origin="lower", ) if colorbar: @@ -232,7 +230,7 @@ def draw_property_layers( if isinstance(cmap, list): cmap = LinearSegmentedColormap.from_list(layer_name, cmap) im = ax.imshow( - data, + data.T, cmap=cmap, alpha=alpha, vmin=vmin, From 1ea215d0b68620ba90942b149031f2a2b0ae90a7 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Thu, 23 Jan 2025 09:35:10 +0100 Subject: [PATCH 3/4] Update mpl_space_drawing.py --- mesa/visualization/mpl_space_drawing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index 9b86ea98311..89ba8578196 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -192,7 +192,7 @@ def draw_property_layers( data = layer.data.astype(float) if layer.data.dtype == bool else layer.data - if space.dimensions != data.shape: + if (space.width, space.height) != data.shape: warnings.warn( f"Layer {layer_name} dimensions ({data.shape}) do not match space dimensions ({width}, {height}).", UserWarning, From 9a165eb831a5e86adc8e05f11fa8b286fcfd7a06 Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Thu, 23 Jan 2025 11:05:29 +0100 Subject: [PATCH 4/4] Update mpl_space_drawing.py --- mesa/visualization/mpl_space_drawing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mesa/visualization/mpl_space_drawing.py b/mesa/visualization/mpl_space_drawing.py index 89ba8578196..11100e6d104 100644 --- a/mesa/visualization/mpl_space_drawing.py +++ b/mesa/visualization/mpl_space_drawing.py @@ -194,7 +194,7 @@ def draw_property_layers( if (space.width, space.height) != data.shape: warnings.warn( - f"Layer {layer_name} dimensions ({data.shape}) do not match space dimensions ({width}, {height}).", + f"Layer {layer_name} dimensions ({data.shape}) do not match space dimensions ({space.width}, {space.height}).", UserWarning, stacklevel=2, ) @@ -207,6 +207,7 @@ def draw_property_layers( # Draw the layer if "color" in portrayal: + data = data.T rgba_color = to_rgba(portrayal["color"]) normalized_data = (data - vmin) / (vmax - vmin) rgba_data = np.full((*data.shape, 4), rgba_color) @@ -216,7 +217,7 @@ def draw_property_layers( layer_name, [(0, 0, 0, 0), (*rgba_color[:3], alpha)] ) im = ax.imshow( - rgba_data.T, + rgba_data, origin="lower", ) if colorbar: