From 2e7909dbe974a7582b2cd52ecb3202908a23a25b Mon Sep 17 00:00:00 2001 From: Rike-Benjamin Schuppner Date: Fri, 12 Jul 2024 12:39:10 +0200 Subject: [PATCH] Improved draw_coords function --- notebooks/nb1_matplotlib_and_numpy.ipynb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/notebooks/nb1_matplotlib_and_numpy.ipynb b/notebooks/nb1_matplotlib_and_numpy.ipynb index 6bfe445..0bf4d73 100644 --- a/notebooks/nb1_matplotlib_and_numpy.ipynb +++ b/notebooks/nb1_matplotlib_and_numpy.ipynb @@ -61,13 +61,13 @@ }, "outputs": [], "source": [ - "def draw_coords(coords, ax, params={}):\n", + "def draw_coords(ax, coords, **params):\n", " \"\"\"\n", " Takes a list of coordinates and draws them as scatter elements onto a pyplot ax object\n", "\n", " Input:\n", - " - coords: list of tuples of x,y coordinates\n", " - ax: a pyplot ax object\n", + " - coords: list of tuples of x,y coordinates\n", " - params: parameters to be passed to the scatter function (e.g. shape, size, color, etc.)\n", " Returns:\n", " - ax: a pyplot ax object\n", @@ -104,7 +104,7 @@ " - bot : pelita bot object\n", " - ax : a pyplot axis object\n", " Returns:\n", - " -ax : a pyplot axis object\n", + " - ax : a pyplot axis object\n", " \"\"\"\n", " # Depending which team we are, we need to color the board appropriately\n", " if bot.is_blue:\n", @@ -124,13 +124,13 @@ "\n", " # Then we call the draw_coords function for each type of element we want to draw.\n", " # Each can be customized with whichever color, shape and size you want.\n", - " ax = draw_coords([bot.position], ax, {\"c\": col_home_b1, \"marker\": \"*\", \"s\": 400})\n", - " ax = draw_coords(bot.walls, ax, {\"c\": \"black\", \"marker\": \"s\", \"s\": 250})\n", - " ax = draw_coords([bot.other.position], ax, {\"c\": col_home_b2, \"marker\": \"*\", \"s\": 400})\n", - " ax = draw_coords(bot.food, ax, {\"c\": col_home_food, \"s\": 100})\n", - " ax = draw_coords(bot.enemy[0].food, ax, {\"c\": col_enemy_food, \"s\": 100})\n", - " ax = draw_coords([bot.enemy[0].position], ax, {\"c\": col_enemy_b1, \"marker\": \"*\", \"s\": 400})\n", - " ax = draw_coords([bot.enemy[1].position], ax, {\"c\": col_enemy_b2, \"marker\": \"*\", \"s\": 400})\n", + " ax = draw_coords(ax, [bot.position], c=col_home_b1, marker=\"*\", s=400)\n", + " ax = draw_coords(ax, bot.walls, c=\"black\", marker=\"s\", s=250)\n", + " ax = draw_coords(ax, [bot.other.position], c=col_home_b2, marker=\"*\", s=400)\n", + " ax = draw_coords(ax, bot.food, c=col_home_food, s=100)\n", + " ax = draw_coords(ax, bot.enemy[0].food, c=col_enemy_food, s=100)\n", + " ax = draw_coords(ax, [bot.enemy[0].position], c=col_enemy_b1, marker=\"*\", s=400)\n", + " ax = draw_coords(ax, [bot.enemy[1].position], c=col_enemy_b2, marker=\"*\", s=400)\n", " ax.axvline(np.sum(ax.get_xlim()) / 2, c=\"black\")\n", " # This is to get the coordinate system to have it's origin in the top left\n", " yd, yu = ax.get_ylim()\n",