Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use an image as a vertex label in a graph?

Exactly what the title says. I have a graph, but I'd like to change the labels of the vertices so that I can display my own images at each vertex.

I figured something like the code below would work, but instead of showing the images at the vertices, I see a string of where the image is located in memory.

from PIL import Image

H = Graph({img0:[1], 1:[2], 2:[3]})

img0 = Image.open('image0.png')
img1 = Image.open('image1.png')
img2 = Image.open('image2.png')
img3 = Image.open('image3.png')

img_list = [img0 ,img1, img2, img3]

def my_label_function (vertex_number):
    return img_list[vertex_number]

H.relabel(my_label_function)

H.plot()