prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Getting 403 Forbidden errors when running plot_custom_node_icons example
  The way `plot_custom_node_icons` is currently set up, we grab resources from `materialsui.com` every time anyone runs this example which of course includes our own CI runs. We are now getting 403 forbidden errors (rightly so) since we are accessing these resources programatically. I can think of 2 ways around this:
   1) Store the icon png's locally so we're not constantly having to download them from an external source
   2) Add header spoofing to the url request.
  
  Though it makes the example a bit larger, I prefer option 1). The second option would add boilerplate to the example, and isn't exactly setting an example of good web citizenship. I'm certainly open to other ideas though!
  
  </issue>
  <code>
  [start of examples/drawing/plot_custom_node_icons.py]
  1 """
  2 =================
  3 Custom node icons
  4 =================
  5 
  6 Example of using custom icons to represent nodes with matplotlib.
  7 """
  8 
  9 import matplotlib.pyplot as plt
  10 import networkx as nx
  11 import PIL
  12 import urllib.request
  13 
  14 # Image URLs for graph nodes
  15 icon_urls = {
  16     "router": "https://www.materialui.co/materialIcons/hardware/router_black_144x144.png",
  17     "switch": "https://www.materialui.co/materialIcons/action/dns_black_144x144.png",
  18     "PC": "https://www.materialui.co/materialIcons/hardware/computer_black_144x144.png",
  19 }
  20 
  21 # Load images from web
  22 images = {
  23     k: PIL.Image.open(urllib.request.urlopen(url)) for k, url in icon_urls.items()
  24 }
  25 
  26 # Generate the computer network graph
  27 G = nx.Graph()
  28 
  29 G.add_node("router", image=images["router"])
  30 for i in range(1, 4):
  31     G.add_node(f"switch_{i}", image=images["switch"])
  32     for j in range(1, 4):
  33         G.add_node("PC_" + str(i) + "_" + str(j), image=images["PC"])
  34 
  35 G.add_edge("router", "switch_1")
  36 G.add_edge("router", "switch_2")
  37 G.add_edge("router", "switch_3")
  38 for u in range(1, 4):
  39     for v in range(1, 4):
  40         G.add_edge("switch_" + str(u), "PC_" + str(u) + "_" + str(v))
  41 
  42 # get layout and draw edges
  43 pos = nx.spring_layout(G)
  44 fig, ax = plt.subplots()
  45 nx.draw_networkx_edges(G, pos=pos, ax=ax, min_source_margin=15, min_target_margin=15)
  46 
  47 # Transform from data coordinates (scaled between xlim and ylim) to display coordinates
  48 tr_figure = ax.transData.transform
  49 # Transform from display to figure coordinates
  50 tr_axes = fig.transFigure.inverted().transform
  51 
  52 # Select the size of the image (relative to the X axis)
  53 icon_size = (ax.get_xlim()[1] - ax.get_xlim()[0]) * 0.025
  54 icon_center = icon_size / 2.0
  55 
  56 # Add the respective image to each node
  57 for n in G.nodes:
  58     xf, yf = tr_figure(pos[n])
  59     xa, ya = tr_axes((xf, yf))
  60     # get overlapped axes and plot icon
  61     a = plt.axes([xa - icon_center, ya - icon_center, icon_size, icon_size])
  62     a.imshow(G.nodes[n]["image"])
  63     a.axis("off")
  64 plt.show()
  65
  [end of examples/drawing/plot_custom_node_icons.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/examples/drawing/plot_custom_node_icons.py b/examples/drawing/plot_custom_node_icons.py
  --- a/examples/drawing/plot_custom_node_icons.py
  +++ b/examples/drawing/plot_custom_node_icons.py
  @@ -4,24 +4,23 @@
   =================
   
   Example of using custom icons to represent nodes with matplotlib.
  +
  +Images for node icons courtesy of www.materialui.co
   """
   
   import matplotlib.pyplot as plt
   import networkx as nx
   import PIL
  -import urllib.request
   
   # Image URLs for graph nodes
  -icon_urls = {
  -    "router": "https://www.materialui.co/materialIcons/hardware/router_black_144x144.png",
  -    "switch": "https://www.materialui.co/materialIcons/action/dns_black_144x144.png",
  -    "PC": "https://www.materialui.co/materialIcons/hardware/computer_black_144x144.png",
  +icons = {
  +    "router": "icons/router_black_144x144.png",
  +    "switch": "icons/switch_black_144x144.png",
  +    "PC": "icons/computer_black_144x144.png",
   }
   
  -# Load images from web
  -images = {
  -    k: PIL.Image.open(urllib.request.urlopen(url)) for k, url in icon_urls.items()
  -}
  +# Load images
  +images = {k: PIL.Image.open(fname) for k, fname in icons.items()}
   
   # Generate the computer network graph
   G = nx.Graph()
  @@ -39,10 +38,22 @@
       for v in range(1, 4):
           G.add_edge("switch_" + str(u), "PC_" + str(u) + "_" + str(v))
   
  -# get layout and draw edges
  -pos = nx.spring_layout(G)
  +# Get a reproducible layout and create figure
  +pos = nx.spring_layout(G, seed=1734289230)
   fig, ax = plt.subplots()
  -nx.draw_networkx_edges(G, pos=pos, ax=ax, min_source_margin=15, min_target_margin=15)
  +
  +# Note: the min_source/target_margin kwargs only work with FancyArrowPatch objects.
  +# Force the use of FancyArrowPatch for edge drawing by setting `arrows=True`,
  +# but suppress arrowheads with `arrowstyle="-"`
  +nx.draw_networkx_edges(
  +    G,
  +    pos=pos,
  +    ax=ax,
  +    arrows=True,
  +    arrowstyle="-",
  +    min_source_margin=15,
  +    min_target_margin=15,
  +)
   
   # Transform from data coordinates (scaled between xlim and ylim) to display coordinates
   tr_figure = ax.transData.transform
  
verification_info: {"golden_diff": "diff --git a/examples/drawing/plot_custom_node_icons.py b/examples/drawing/plot_custom_node_icons.py\n--- a/examples/drawing/plot_custom_node_icons.py\n+++ b/examples/drawing/plot_custom_node_icons.py\n@@ -4,24 +4,23 @@\n =================\n \n Example of using custom icons to represent nodes with matplotlib.\n+\n+Images for node icons courtesy of www.materialui.co\n \"\"\"\n \n import matplotlib.pyplot as plt\n import networkx as nx\n import PIL\n-import urllib.request\n \n # Image URLs for graph nodes\n-icon_urls = {\n-    \"router\": \"https://www.materialui.co/materialIcons/hardware/router_black_144x144.png\",\n-    \"switch\": \"https://www.materialui.co/materialIcons/action/dns_black_144x144.png\",\n-    \"PC\": \"https://www.materialui.co/materialIcons/hardware/computer_black_144x144.png\",\n+icons = {\n+    \"router\": \"icons/router_black_144x144.png\",\n+    \"switch\": \"icons/switch_black_144x144.png\",\n+    \"PC\": \"icons/computer_black_144x144.png\",\n }\n \n-# Load images from web\n-images = {\n-    k: PIL.Image.open(urllib.request.urlopen(url)) for k, url in icon_urls.items()\n-}\n+# Load images\n+images = {k: PIL.Image.open(fname) for k, fname in icons.items()}\n \n # Generate the computer network graph\n G = nx.Graph()\n@@ -39,10 +38,22 @@\n     for v in range(1, 4):\n         G.add_edge(\"switch_\" + str(u), \"PC_\" + str(u) + \"_\" + str(v))\n \n-# get layout and draw edges\n-pos = nx.spring_layout(G)\n+# Get a reproducible layout and create figure\n+pos = nx.spring_layout(G, seed=1734289230)\n fig, ax = plt.subplots()\n-nx.draw_networkx_edges(G, pos=pos, ax=ax, min_source_margin=15, min_target_margin=15)\n+\n+# Note: the min_source/target_margin kwargs only work with FancyArrowPatch objects.\n+# Force the use of FancyArrowPatch for edge drawing by setting `arrows=True`,\n+# but suppress arrowheads with `arrowstyle=\"-\"`\n+nx.draw_networkx_edges(\n+    G,\n+    pos=pos,\n+    ax=ax,\n+    arrows=True,\n+    arrowstyle=\"-\",\n+    min_source_margin=15,\n+    min_target_margin=15,\n+)\n \n # Transform from data coordinates (scaled between xlim and ylim) to display coordinates\n tr_figure = ax.transData.transform\n", "issue": "Getting 403 Forbidden errors when running plot_custom_node_icons example\nThe way `plot_custom_node_icons` is currently set up, we grab resources from `materialsui.com` every time anyone runs this example which of course includes our own CI runs. We are now getting 403 forbidden errors (rightly so) since we are accessing these resources programatically. I can think of 2 ways around this:\r\n 1) Store the icon png's locally so we're not constantly having to download them from an external source\r\n 2) Add header spoofing to the url request.\r\n\r\nThough it makes the example a bit larger, I prefer option 1). The second option would add boilerplate to the example, and isn't exactly setting an example of good web citizenship. I'm certainly open to other ideas though!\n", "before_files": [{"content": "\"\"\"\n=================\nCustom node icons\n=================\n\nExample of using custom icons to represent nodes with matplotlib.\n\"\"\"\n\nimport matplotlib.pyplot as plt\nimport networkx as nx\nimport PIL\nimport urllib.request\n\n# Image URLs for graph nodes\nicon_urls = {\n    \"router\": \"https://www.materialui.co/materialIcons/hardware/router_black_144x144.png\",\n    \"switch\": \"https://www.materialui.co/materialIcons/action/dns_black_144x144.png\",\n    \"PC\": \"https://www.materialui.co/materialIcons/hardware/computer_black_144x144.png\",\n}\n\n# Load images from web\nimages = {\n    k: PIL.Image.open(urllib.request.urlopen(url)) for k, url in icon_urls.items()\n}\n\n# Generate the computer network graph\nG = nx.Graph()\n\nG.add_node(\"router\", image=images[\"router\"])\nfor i in range(1, 4):\n    G.add_node(f\"switch_{i}\", image=images[\"switch\"])\n    for j in range(1, 4):\n        G.add_node(\"PC_\" + str(i) + \"_\" + str(j), image=images[\"PC\"])\n\nG.add_edge(\"router\", \"switch_1\")\nG.add_edge(\"router\", \"switch_2\")\nG.add_edge(\"router\", \"switch_3\")\nfor u in range(1, 4):\n    for v in range(1, 4):\n        G.add_edge(\"switch_\" + str(u), \"PC_\" + str(u) + \"_\" + str(v))\n\n# get layout and draw edges\npos = nx.spring_layout(G)\nfig, ax = plt.subplots()\nnx.draw_networkx_edges(G, pos=pos, ax=ax, min_source_margin=15, min_target_margin=15)\n\n# Transform from data coordinates (scaled between xlim and ylim) to display coordinates\ntr_figure = ax.transData.transform\n# Transform from display to figure coordinates\ntr_axes = fig.transFigure.inverted().transform\n\n# Select the size of the image (relative to the X axis)\nicon_size = (ax.get_xlim()[1] - ax.get_xlim()[0]) * 0.025\nicon_center = icon_size / 2.0\n\n# Add the respective image to each node\nfor n in G.nodes:\n    xf, yf = tr_figure(pos[n])\n    xa, ya = tr_axes((xf, yf))\n    # get overlapped axes and plot icon\n    a = plt.axes([xa - icon_center, ya - icon_center, icon_size, icon_size])\n    a.imshow(G.nodes[n][\"image\"])\n    a.axis(\"off\")\nplt.show()\n", "path": "examples/drawing/plot_custom_node_icons.py"}]}