Closed Franck-Delaplace closed 3 months ago
Hi, thanks for raising the issue. A few questions before I dive in:
pip install https://github.com/paulbrodersen/netgraph/archive/dev.zip
Hi, thanks for raising the issue. A few questions before I dive in:
- What are the versions of PyQt (assuming you are still using PyQt), matplotlib, and netgraph that your using?
- Does the issue persist if you install netgraph from the dev branch?
pip install https://github.com/paulbrodersen/netgraph/archive/dev.zip
- Does the issue persist if you install the version from the dev branch AND use a different interactive backend?
What about:
- Does the issue persist if you install the version from the dev branch AND use a different interactive backend?
I am sorry, I am unable to answer. I use the dev branch but I don't know what you mean when you talk about interactive backend. I am a beginner in python and netgraph.
No worries, you are doing great. You can read about matplotlib backends here.
I suspect that the issue arises because of the PyQt backend you are using in your application. I would like you to test a minimum working example with a different backend to confirm that suspicion. For example:
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
from netgraph import InteractiveGraph
g = InteractiveGraph([(0, 1)], node_labels=True)
plt.show()
# increase the size of the window
I finally understand your question my backend is "Qt5Agg". You can find the whole application dedicated to genetic network analysis where I use EditGraph there : https://github.com/Franck-Delaplace/BooN
Have you tried running the code snippet?
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
from netgraph import InteractiveGraph
g = InteractiveGraph([(0, 1)], node_labels=True)
plt.show()
# increase the size of the window
Not yet, I am too busy, I will try soon Best Franck
Franck Delaplace, PhD. Le 12 mars 2024 à 12:23 +0100, Paul Brodersen @.***>, a écrit :
Have you tried running the code snippet? import matplotlib matplotlib.use('tkagg')
import matplotlib.pyplot as plt from netgraph import InteractiveGraph
g = InteractiveGraph([(0, 1)], node_labels=True) plt.show()
increase the size of the window
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
I have finally tested the program, The size of the nodes grows as well as the size of the font.
Le mar. 12 mars 2024 à 11:58, Paul Brodersen @.***> a écrit :
No worries, you are doing great. You can read about matplotlib backends here https://matplotlib.org/stable/users/explain/figure/backends.html.
I suspect that the issue arises because of the PyQt backend you are using in your application. I would like you to test a minimum working example with a different backend to confirm that suspicion. For example:
import matplotlib matplotlib.use('tkagg')
import matplotlib.pyplot as plt from netgraph import InteractiveGraph
g = InteractiveGraph([(0, 1)], node_labels=True) plt.show()
increase the size of the window
— Reply to this email directly, view it on GitHub https://github.com/paulbrodersen/netgraph/issues/87#issuecomment-1991366725, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6RWCKKRVRMG3F2TDDQKNZLYX3NV5AVCNFSM6AAAAABEJKVJL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJRGM3DMNZSGU . You are receiving this because you authored the thread.Message ID: @.***>
-- Franck Delaplace, Ph. D.
However if I change the backend i.e. matplotlib.use("Qt5Agg")
I have the
same behavior as using 'tkagg'
. The size of the nodes and the font grow.
Le mar. 12 mars 2024 à 12:23, Paul Brodersen @.***> a écrit :
Have you tried running the code snippet?
import matplotlib matplotlib.use('tkagg')
import matplotlib.pyplot as plt from netgraph import InteractiveGraph
g = InteractiveGraph([(0, 1)], node_labels=True) plt.show()
increase the size of the window
— Reply to this email directly, view it on GitHub https://github.com/paulbrodersen/netgraph/issues/87#issuecomment-1991423405, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6RWCKMMGVJLVCHR647MFL3YX3QSPAVCNFSM6AAAAABEJKVJL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJRGQZDGNBQGU . You are receiving this because you authored the thread.Message ID: @.***>
-- Franck Delaplace, Ph. D.
So you no longer observe the behaviour you originally reported?
However, when the window is scaled, the nodes become disproportionately large compared to the labels, which remain the same size.
In my application yes, but not in your example. However, in my application the font size is fixed as parameters.
Franck Delaplace, PhD. Le 25 mars 2024 à 12:08 +0100, Paul Brodersen @.***>, a écrit :
So you no longer observe the behaviour you originally reported?
However, when the window is scaled, the nodes become disproportionately large compared to the labels, which remain the same size. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
Well, if you keep the font-sized fixed, then any zoom event will result in a mismatch between node sizes and font sizes. There isn't much that can be done then.
There isn't much that can be done then.
On further reflection, it might be doable. The basic strategy is the following:
1) Keep track of node sizes in display units.
node_size_in_data_units = [node : artist.size for node, artist in my_graph_instance["node_artists"].items()]
transform = ... # TODO: https://matplotlib.org/stable/users/explain/artists/transforms_tutorial.html
node_size_in_display_units = [node : transform(size) for node, size for node_size_in_data_units.items()]
2) Add a callback, such that on every zoom event, you compute the new node size(s) in display units. Compute the ratio between old and new node sizes.
3) Redraw the graph with the new node sizes: my_graph_instance = EditableGraph(..., node_size=old_node_size * ratio, ...)
Based on this code closed to yours since I simply add node_label_offset=(0., 0.05)
from netgraph import InteractiveGraph
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
g = InteractiveGraph([(0, 1)], node_labels=True, node_label_offset=(0., 0.05))
plt.show()
In this case, the font size remains constant even when the window is enlarged. However, if I replace (0., 0.05)
with (0., 0.)
, the font size increases proportionally with the window size again. I think that the origin comes from the position of the node label when it is not at the center of the node. Please test it.
What you describe is the intended behaviour: if node labels fill the node artists, then upon zoom events, node label font sizes are adjusted. If the labels are outside the node artists, the font sizes are not adjusted.
Thank you, I do not know this element. However it's annoying.
Le mer. 27 mars 2024 à 10:55, Paul Brodersen @.***> a écrit :
What you describe is the intended behaviour: if node labels fill the node artists, then upon zoom events, node label font sizes are adjusted. If the labels are outside the node artists, the font sizes are not adjusted.
— Reply to this email directly, view it on GitHub https://github.com/paulbrodersen/netgraph/issues/87#issuecomment-2022350051, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6RWCKMR3O5GLNBOTGSCXDDY2KCQHAVCNFSM6AAAAABEJKVJL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRSGM2TAMBVGE . You are receiving this because you authored the thread.Message ID: @.***>
-- Franck Delaplace, Ph. D.
Closing the issue for now, as most of your problems seem to stem from intended behaviour, not a bug. If I have misunderstood the issue(s), or you have any other questions on this specific topic, feel free to re-open.
I use
Netgraph
(EditableGraph
) to represent networks. However, when the window is scaled, the nodes become disproportionately large compared to the labels, which remain the same size. This results in an unappealing visual representation.How to keep the size of nodes invariant in Python, i.e. insensitive to the window size scaling ? Thank you for your answer.