-
Notifications
You must be signed in to change notification settings - Fork 38
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
Fit/scale an InteractiveGraph to its matplotlib axe #42
Comments
Netgraph doesn't (or shouldn't) but it is built on matplotlib, and matplotlib by default adjusts the axis extents to the data limits of the objects plotted. As with any other matplotlib figure, you can set the x- and y-limits explicitly: import matplotlib.pyplot as plt
import networkx as nx
from netgraph import InteractiveGraph
fig, ax = plt.subplots()
G = nx.complete_graph(10)
pos = nx.shell_layout(G)
ref = InteractiveGraph(G, node_layout=pos, ax=ax)
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
plt.show() Does this solve your issue? |
As always, thank you for your (quick) answer. I can see that it works, I just have to figure out how to properly set it to the matplotlib limits (there is currently still some margin). I initialized my Figure to figsize=(5, 3) so maybe I have to dig with this. All these features is just some extensive stuff I have added to my work but is not my core knowledge so it's not very intuitive to me. By the way, setting the axe xlim/ylim impacted my graph "size", everything got way smaller than it was. Any clue why it did? |
In matplotlib, all axes have a margin by default. You can adjust/remove the margins with: fig, ax = plt.subplots()
fig.subplots_adjust(left=0, bottom=0, right=1, top=1)
This is the expected behaviour, as in netgraph, all object sizes are given in data coordinates (times a constant factor of 0.01). This is in contrast to networkx, where node sizes and edge widths are in display coordinates. |
Thanks for your explanation. I already set plot with the subplots_adjust method. I've also adjusted origin and scale to it so I'm pretty satisfied with it, I have way less coordinates issues than previously. I guess you can close the issue, since behaviour seems to be pretty much what I wanted! |
First, sorry if raising an issue is not the proper way to log my question.
I have a PyQt app where I draw graphs with various number of nodes.
After determining the nodes positions (in my case using nx.shell_layout(G)), I draw an InteractiveGraph (thanks to your advice on a SO question I opened a few days ago) and it works fine.
However, I can see that the graph is not "adjusted" to the matplotlib canvas it is attached to. It seems to me that netgraph (or networkx) auto determines a "frame" depending on the number of nodes it has to display. So when you click/move the nodes, they are not "displayed" if you moved outside of this frame, which is smaller than my overall matplotlib size.
So I would like to know if there is a way to adjust this frame (or box) so that its limits fit the one of my matplotlib canvas?
The text was updated successfully, but these errors were encountered: