0

I am writing a program which generates satisfiable models (connected graphs) for a specific input string. The details here are not important but the main problem is that each node has a label and such label can be lengthy one. So, what happens is that it does not fit into the figure which results in displaying all the nodes but some labels are partly displayed... Also, the figure that is displayed does not provide an option to zoom out so it is impossible to capture entire graph with full labels on one figure.

Can someone help me out and perhaps suggest a solution?

for i in range(0,len(Graphs)):
    graph = Graphs[i]

    custom_labels={}
    node_colours=['y']
    for node in graph.nodes():
        custom_labels[node] = graph.node[node]
        node_colours.append('c')
    #nx.circular_layout(Graphs[i])

    nx.draw(Graphs[i], nx.circular_layout(Graphs[i]), node_size=1500, with_labels=True, labels = custom_labels, node_color=node_colours)
    #show with custom labels
    fig_name = "graph" + str(i) + ".png"
    #plt.savefig(fig_name)
    plt.show()

Update picture added: enter image description here

1

2 Answers 2

1

You could scale the figure

import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()
G.add_edge('a'*50,'b'*50)
nx.draw(G,with_labels=True)
plt.savefig('before.png')
l,r = plt.xlim()
print(l,r)
plt.xlim(l-2,r+2)
plt.savefig('after.png')

before enter image description here

after enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I have to say it is something that I didn't think of and it works well enough that I can accept it as an answer. I don't think there is a better solution to this problem.
0

You could reduce the font size, using the font_size parameter:

nx.draw(Graphs[i], nx.circular_layout(Graphs[i]), ... , font_size=6)

5 Comments

but is the a way that the figure itself will make sure that it displays all the node and full labels?
@aki could you make a small copy-pastable example to illustrate what is going wrong?
picture added, it is impossible to zoom out so that I can save entire graph. So is there another solution?
@aki could you add MCVE copy-pastable code as well?
it would be better if you could look here: github.com/marcincuber/modal_logic and then just run logic_T and you can see exactly what is happening

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.