I am generating simple syntactic dependecies trees such as in the following example:
Best layout is "dot" but on the top row things get very crowded. Is there any parameter or other way to avoid node labels overlapping with neighbouring nodes (and ideally edges)?
Maybe some matplotlib parameter to "draw on a very wide canvas"? (sorry totally matplotlib ignorant).
Here is the code I am currently using:
import platform
import matplotlib
import matplotlib.pyplot as plt
import stanza
import networkx as nx
from netgraph import InteractiveGraph
if platform.system() == "Darwin":
matplotlib.use("TkAgg") # MacOSX backend is bugged; use TkAgg
def display_graph(G: nx.DiGraph, title: str):
"""Use netgraph to show the graph"""
nodecolors = nx.get_node_attributes(G, "nodecol")
nodelabels = nx.get_node_attributes(G, "lemma")
nodeshapes = nx.get_node_attributes(G, "nodeshape")
edgelabels = nx.get_edge_attributes(G, "label")
# now plot the graph
plot_instance = InteractiveGraph(
G,
node_layout="dot",
node_labels=nodelabels,
node_color=nodecolors,
node_label_fontdict=dict(size=12),
node_shape=nodeshapes,
node_alpha=0.5, # node transparency
edge_labels=edgelabels,
edge_layout="curved",
arrows=True,
)
plt.suptitle(title, wrap=True)
plt.show()
return