Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set width and heights for nodes with images propertly? #435

Open
uduse opened this issue Aug 25, 2022 · 0 comments
Open

How to set width and heights for nodes with images propertly? #435

uduse opened this issue Aug 25, 2022 · 0 comments

Comments

@uduse
Copy link

uduse commented Aug 25, 2022

The script looks roughly like follows:

graph = pygraphviz.AGraph(directed=True, imagepath=image_dir, dpi=72)
graph.node_attr.update(
    imagescale=True,
    shape="box",
    imagepos="tc",
    fixed_size=True,
    labelloc="b",
    fontname="Courier New",
)
graph.edge_attr.update(fontname="Courier New")

graph.add_node(0, label="some label", width=2.5, height=4, image="image_path")
# Add all other nodes and connect them up.
for i, node in enumerate(nodes):
    graph.add_node(
        i + 1,
        label="some other label",
        width=2.5,
        height=4,
        image="image_path"
    )

However, when I generate the DOT file with the script, the width and height are overwritten to a different number for all nodes like this:

...
	146	[height=4,
		image="image_path",
		label="some_label",
		pos="2309,11952",
		width=3.5];
...

The magic numbers width=2.5, height=4 are picked by me through trials and error to generate a good looking graph. However, when I resize the image, the whole thing changes disproportionally.

Before I resize the image:
image

After I resize the image and changed the DPI:
image

What I want to achieve is to set a fixed size for the nodes (the labels are usually the same size), and let the image fill the top half of the node as much as possible keeping aspect ratio. Is there a better way of doing this? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant