We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
JupyterViz space view limits
**What's the problem this feature will solve?**
At the moment, when drawing spaces with JupyterViz, the axes limits are left to be automatically determined by Matplotlib. Would it not make more sense (in particular of continuous spaces, to derive xlim and xmax from the space itself?

**Describe the solution you'd like**
The simplest fix would be to adapt `_draw_grid` to use `space.width` and `space.height` while `_draw_continuos_space` uses `space.x_min`, `space.x_max`, `space.y_min`, and `space.y_max`. Are there reasons where the user might want to rely on matpltolib's automatic determination of the bounds? If so, then a slightly more sophisticated solution would be needed where kwargs are passed to from jupyterviz to the underlying space_drawer function. So you would add a `space_drawer_kwargs` keyword argument.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mesa/experimental/components/matplotlib.py`
Content:
```
1 from typing import Optional
2 
3 import networkx as nx
4 import solara
5 from matplotlib.figure import Figure
6 from matplotlib.ticker import MaxNLocator
7 
8 import mesa
9 
10 
11 @solara.component
12 def SpaceMatplotlib(model, agent_portrayal, dependencies: Optional[list[any]] = None):
13     space_fig = Figure()
14     space_ax = space_fig.subplots()
15     space = getattr(model, "grid", None)
16     if space is None:
17         # Sometimes the space is defined as model.space instead of model.grid
18         space = model.space
19     if isinstance(space, mesa.space.NetworkGrid):
20         _draw_network_grid(space, space_ax, agent_portrayal)
21     elif isinstance(space, mesa.space.ContinuousSpace):
22         _draw_continuous_space(space, space_ax, agent_portrayal)
23     else:
24         _draw_grid(space, space_ax, agent_portrayal)
25     space_ax.set_axis_off()
26     solara.FigureMatplotlib(space_fig, format="png", dependencies=dependencies)
27 
28 
29 def _draw_grid(space, space_ax, agent_portrayal):
30     def portray(g):
31         x = []
32         y = []
33         s = []  # size
34         c = []  # color
35         for i in range(g.width):
36             for j in range(g.height):
37                 content = g._grid[i][j]
38                 if not content:
39                     continue
40                 if not hasattr(content, "__iter__"):
41                     # Is a single grid
42                     content = [content]
43                 for agent in content:
44                     data = agent_portrayal(agent)
45                     x.append(i)
46                     y.append(j)
47                     if "size" in data:
48                         s.append(data["size"])
49                     if "color" in data:
50                         c.append(data["color"])
51         out = {"x": x, "y": y}
52         if len(s) > 0:
53             out["s"] = s
54         if len(c) > 0:
55             out["c"] = c
56         return out
57 
58     space_ax.scatter(**portray(space))
59 
60 
61 def _draw_network_grid(space, space_ax, agent_portrayal):
62     graph = space.G
63     pos = nx.spring_layout(graph, seed=0)
64     nx.draw(
65         graph,
66         ax=space_ax,
67         pos=pos,
68         **agent_portrayal(graph),
69     )
70 
71 
72 def _draw_continuous_space(space, space_ax, agent_portrayal):
73     def portray(space):
74         x = []
75         y = []
76         s = []  # size
77         c = []  # color
78         for agent in space._agent_to_index:
79             data = agent_portrayal(agent)
80             _x, _y = agent.pos
81             x.append(_x)
82             y.append(_y)
83             if "size" in data:
84                 s.append(data["size"])
85             if "color" in data:
86                 c.append(data["color"])
87         out = {"x": x, "y": y}
88         if len(s) > 0:
89             out["s"] = s
90         if len(c) > 0:
91             out["c"] = c
92         return out
93 
94     space_ax.scatter(**portray(space))
95 
96 
97 def make_plot(model, measure):
98     fig = Figure()
99     ax = fig.subplots()
100     df = model.datacollector.get_model_vars_dataframe()
101     if isinstance(measure, str):
102         ax.plot(df.loc[:, measure])
103         ax.set_ylabel(measure)
104     elif isinstance(measure, dict):
105         for m, color in measure.items():
106             ax.plot(df.loc[:, m], label=m, color=color)
107         fig.legend()
108     elif isinstance(measure, (list, tuple)):
109         for m in measure:
110             ax.plot(df.loc[:, m], label=m)
111         fig.legend()
112     # Set integer x axis
113     ax.xaxis.set_major_locator(MaxNLocator(integer=True))
114     solara.FigureMatplotlib(fig)
115
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py
--- a/mesa/experimental/components/matplotlib.py
+++ b/mesa/experimental/components/matplotlib.py
@@ -55,6 +55,8 @@
             out["c"] = c
         return out
 
+    space_ax.set_xlim(-1, space.width)
+    space_ax.set_ylim(-1, space.height)
     space_ax.scatter(**portray(space))
 
 
@@ -91,6 +93,14 @@
             out["c"] = c
         return out
 
+    width = space.x_max - space.x_min
+    x_padding = width / 20
+    height = space.y_max - space.y_min
+    y_padding = height / 20
+    space_ax.set_xlim(space.x_min - x_padding, space.x_max + x_padding)
+    space_ax.set_ylim(space.y_min - y_padding, space.y_max + y_padding)
+    space_ax.scatter(**portray(space))
+
     space_ax.scatter(**portray(space))

{"golden_diff": "diff --git a/mesa/experimental/components/matplotlib.py b/mesa/experimental/components/matplotlib.py\n--- a/mesa/experimental/components/matplotlib.py\n+++ b/mesa/experimental/components/matplotlib.py\n@@ -55,6 +55,8 @@\n             out[\"c\"] = c\n         return out\n \n+    space_ax.set_xlim(-1, space.width)\n+    space_ax.set_ylim(-1, space.height)\n     space_ax.scatter(**portray(space))\n \n \n@@ -91,6 +93,14 @@\n             out[\"c\"] = c\n         return out\n \n+    width = space.x_max - space.x_min\n+    x_padding = width / 20\n+    height = space.y_max - space.y_min\n+    y_padding = height / 20\n+    space_ax.set_xlim(space.x_min - x_padding, space.x_max + x_padding)\n+    space_ax.set_ylim(space.y_min - y_padding, space.y_max + y_padding)\n+    space_ax.scatter(**portray(space))\n+\n     space_ax.scatter(**portray(space))\n", "issue": "JupyterViz space view limits\n**What's the problem this feature will solve?**\r\nAt the moment, when drawing spaces with JupyterViz, the axes limits are left to be automatically determined by Matplotlib. Would it not make more sense (in particular of continuous spaces, to derive xlim and xmax from the space itself?\r\n\r\n**Describe the solution you'd like**\r\nThe simplest fix would be to adapt `_draw_grid` to use `space.width` and `space.height` while `_draw_continuos_space` uses `space.x_min`, `space.x_max`, `space.y_min`, and `space.y_max`. Are there reasons where the user might want to rely on matpltolib's automatic determination of the bounds? If so, then a slightly more sophisticated solution would be needed where kwargs are passed to from jupyterviz to the underlying space_drawer function. So you would add a `space_drawer_kwargs` keyword argument.\r\n\r\n\n", "before_files": [{"content": "from typing import Optional\n\nimport networkx as nx\nimport solara\nfrom matplotlib.figure import Figure\nfrom matplotlib.ticker import MaxNLocator\n\nimport mesa\n\n\n@solara.component\ndef SpaceMatplotlib(model, agent_portrayal, dependencies: Optional[list[any]] = None):\n    space_fig = Figure()\n    space_ax = space_fig.subplots()\n    space = getattr(model, \"grid\", None)\n    if space is None:\n        # Sometimes the space is defined as model.space instead of model.grid\n        space = model.space\n    if isinstance(space, mesa.space.NetworkGrid):\n        _draw_network_grid(space, space_ax, agent_portrayal)\n    elif isinstance(space, mesa.space.ContinuousSpace):\n        _draw_continuous_space(space, space_ax, agent_portrayal)\n    else:\n        _draw_grid(space, space_ax, agent_portrayal)\n    space_ax.set_axis_off()\n    solara.FigureMatplotlib(space_fig, format=\"png\", dependencies=dependencies)\n\n\ndef _draw_grid(space, space_ax, agent_portrayal):\n    def portray(g):\n        x = []\n        y = []\n        s = []  # size\n        c = []  # color\n        for i in range(g.width):\n            for j in range(g.height):\n                content = g._grid[i][j]\n                if not content:\n                    continue\n                if not hasattr(content, \"__iter__\"):\n                    # Is a single grid\n                    content = [content]\n                for agent in content:\n                    data = agent_portrayal(agent)\n                    x.append(i)\n                    y.append(j)\n                    if \"size\" in data:\n                        s.append(data[\"size\"])\n                    if \"color\" in data:\n                        c.append(data[\"color\"])\n        out = {\"x\": x, \"y\": y}\n        if len(s) > 0:\n            out[\"s\"] = s\n        if len(c) > 0:\n            out[\"c\"] = c\n        return out\n\n    space_ax.scatter(**portray(space))\n\n\ndef _draw_network_grid(space, space_ax, agent_portrayal):\n    graph = space.G\n    pos = nx.spring_layout(graph, seed=0)\n    nx.draw(\n        graph,\n        ax=space_ax,\n        pos=pos,\n        **agent_portrayal(graph),\n    )\n\n\ndef _draw_continuous_space(space, space_ax, agent_portrayal):\n    def portray(space):\n        x = []\n        y = []\n        s = []  # size\n        c = []  # color\n        for agent in space._agent_to_index:\n            data = agent_portrayal(agent)\n            _x, _y = agent.pos\n            x.append(_x)\n            y.append(_y)\n            if \"size\" in data:\n                s.append(data[\"size\"])\n            if \"color\" in data:\n                c.append(data[\"color\"])\n        out = {\"x\": x, \"y\": y}\n        if len(s) > 0:\n            out[\"s\"] = s\n        if len(c) > 0:\n            out[\"c\"] = c\n        return out\n\n    space_ax.scatter(**portray(space))\n\n\ndef make_plot(model, measure):\n    fig = Figure()\n    ax = fig.subplots()\n    df = model.datacollector.get_model_vars_dataframe()\n    if isinstance(measure, str):\n        ax.plot(df.loc[:, measure])\n        ax.set_ylabel(measure)\n    elif isinstance(measure, dict):\n        for m, color in measure.items():\n            ax.plot(df.loc[:, m], label=m, color=color)\n        fig.legend()\n    elif isinstance(measure, (list, tuple)):\n        for m in measure:\n            ax.plot(df.loc[:, m], label=m)\n        fig.legend()\n    # Set integer x axis\n    ax.xaxis.set_major_locator(MaxNLocator(integer=True))\n    solara.FigureMatplotlib(fig)\n", "path": "mesa/experimental/components/matplotlib.py"}], "after_files": [{"content": "from typing import Optional\n\nimport networkx as nx\nimport solara\nfrom matplotlib.figure import Figure\nfrom matplotlib.ticker import MaxNLocator\n\nimport mesa\n\n\n@solara.component\ndef SpaceMatplotlib(model, agent_portrayal, dependencies: Optional[list[any]] = None):\n    space_fig = Figure()\n    space_ax = space_fig.subplots()\n    space = getattr(model, \"grid\", None)\n    if space is None:\n        # Sometimes the space is defined as model.space instead of model.grid\n        space = model.space\n    if isinstance(space, mesa.space.NetworkGrid):\n        _draw_network_grid(space, space_ax, agent_portrayal)\n    elif isinstance(space, mesa.space.ContinuousSpace):\n        _draw_continuous_space(space, space_ax, agent_portrayal)\n    else:\n        _draw_grid(space, space_ax, agent_portrayal)\n    space_ax.set_axis_off()\n    solara.FigureMatplotlib(space_fig, format=\"png\", dependencies=dependencies)\n\n\ndef _draw_grid(space, space_ax, agent_portrayal):\n    def portray(g):\n        x = []\n        y = []\n        s = []  # size\n        c = []  # color\n        for i in range(g.width):\n            for j in range(g.height):\n                content = g._grid[i][j]\n                if not content:\n                    continue\n                if not hasattr(content, \"__iter__\"):\n                    # Is a single grid\n                    content = [content]\n                for agent in content:\n                    data = agent_portrayal(agent)\n                    x.append(i)\n                    y.append(j)\n                    if \"size\" in data:\n                        s.append(data[\"size\"])\n                    if \"color\" in data:\n                        c.append(data[\"color\"])\n        out = {\"x\": x, \"y\": y}\n        if len(s) > 0:\n            out[\"s\"] = s\n        if len(c) > 0:\n            out[\"c\"] = c\n        return out\n\n    space_ax.set_xlim(-1, space.width)\n    space_ax.set_ylim(-1, space.height)\n    space_ax.scatter(**portray(space))\n\n\ndef _draw_network_grid(space, space_ax, agent_portrayal):\n    graph = space.G\n    pos = nx.spring_layout(graph, seed=0)\n    nx.draw(\n        graph,\n        ax=space_ax,\n        pos=pos,\n        **agent_portrayal(graph),\n    )\n\n\ndef _draw_continuous_space(space, space_ax, agent_portrayal):\n    def portray(space):\n        x = []\n        y = []\n        s = []  # size\n        c = []  # color\n        for agent in space._agent_to_index:\n            data = agent_portrayal(agent)\n            _x, _y = agent.pos\n            x.append(_x)\n            y.append(_y)\n            if \"size\" in data:\n                s.append(data[\"size\"])\n            if \"color\" in data:\n                c.append(data[\"color\"])\n        out = {\"x\": x, \"y\": y}\n        if len(s) > 0:\n            out[\"s\"] = s\n        if len(c) > 0:\n            out[\"c\"] = c\n        return out\n\n    width = space.x_max - space.x_min\n    x_padding = width / 20\n    height = space.y_max - space.y_min\n    y_padding = height / 20\n    space_ax.set_xlim(space.x_min - x_padding, space.x_max + x_padding)\n    space_ax.set_ylim(space.y_min - y_padding, space.y_max + y_padding)\n    space_ax.scatter(**portray(space))\n\n    space_ax.scatter(**portray(space))\n\n\ndef make_plot(model, measure):\n    fig = Figure()\n    ax = fig.subplots()\n    df = model.datacollector.get_model_vars_dataframe()\n    if isinstance(measure, str):\n        ax.plot(df.loc[:, measure])\n        ax.set_ylabel(measure)\n    elif isinstance(measure, dict):\n        for m, color in measure.items():\n            ax.plot(df.loc[:, m], label=m, color=color)\n        fig.legend()\n    elif isinstance(measure, (list, tuple)):\n        for m in measure:\n            ax.plot(df.loc[:, m], label=m)\n        fig.legend()\n    # Set integer x axis\n    ax.xaxis.set_major_locator(MaxNLocator(integer=True))\n    solara.FigureMatplotlib(fig)\n", "path": "mesa/experimental/components/matplotlib.py"}]}