Comments (5)
@maelfabien I figured that the 'issue' with the code above is that the x,y co-ordinates for _ all_ nodes (not just one) needs to be explicitly included. Otherwise, the positions for all nodes are not fixed.
from pyvis.
@maelfabien While I have not experimented with this feature, the VisJS engine apparently can handle that out of the box.
This example demonstrates something similar to what you mentioned, and below is the JavaScript to accompany. It looks like simply supplyingrandomSeed
attribute to the layout
property of the options
object does the trick.
// create an array with nodes
var nodes = new vis.DataSet([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
// create an array with edges
var edges = new vis.DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5}
]);
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {layout:{randomSeed:2}};
var network = new vis.Network(container, data, options);
*EDIT:
I just tried this in a notebook and it seems to work. It is a little awkward to modify the underlying options object of a pyvis network instance due to the current implementation of set_options
but it'll do:
I will leave this open since I want to rewrite the set_options
method to be more user friendly and I could even add a method to support modifying the random seed directly through the network instance :)
from pyvis.
I have a quite similar question, I'm looking for a way to set a seed when building a graph to preserve the same layout between 2 graphs. I haven't found in the code yet where to add this, I'm still looking
from pyvis.
Also, @andrewlaikh it could help to try and turn off the physics with toggle_physics(False)
while supplying x and y coordinates to individual nodes. I am not sure how the VisJS physics engine handles the nodes on their end.
from pyvis.
@boludo00 Thanks for your reply (and sorry for the late reply, I was on holiday). It looks like setting the random seed helps to produce the same graph twice, with similar node positions, when the nodes to plot are exactly the same. What I am currently struggling with is how to make two graphs with mostly similar edges, but some different ones, comparable. For example, I would like to make an explicit visual comparison of these two graphs:
Here's how I build them so far:
G = Network(notebook=True, height="500px", width="100%")
G.set_options('{"layout": {"randomSeed":5}}')
# looping here
...
G.add_node(edg[1], label=edg[1],
x = spk_coord[edg[1]][0], y = spk_coord[edg[1]][1],
)
Where spk_coord
is a dictionary that contains for each character of my network the x and y coordinates, like this:
spk_coord = {
"eddiewillows": [50,50],
"jesseoverton": [50,100],
"conradecklie": [50,150],
"sheriff_brianmobley": [100,50],
"tedgoggle": [100,100],
"lie_detector_operator": [100,150],
"nick": [150,50],
"warrick": [150,100],
"det_oriley": [150,150],
"brass": [200,50],
"tinacollins": [200,100],
"sara": [200,150],
"catherine": [300,50],
"grissom": [300,100],
}
I haven't managed yet to solve this and force the position of x and y to be applied. It looks mostly like the coordinates are not "really" applied, or I might be missing something in the implementation. Would you be able to help with this?
Thanks in advance!
from pyvis.
Related Issues (20)
- Adding and editing nodes and edges graphically HOT 1
- remove print statement
- Intergration with EasyGraph
- Some buttons not working
- Some buttons not working
- Dropdown list button is not precise
- Clustering nodes with same labels?
- Filtering Nodes HOT 1
- Arrows are not displayed on the graph HOT 1
- highlightActive is not defined: Causes wierd jump of graph
- AttributeError: 'NoneType' object has no attribute 'render' HOT 4
- How do you change the fonts of the labels on the nodes?
- Be able to set the color of an edge independently of the source node
- Left to Right Orientation?
- Interactive Node in in Output HOT 1
- Use palette to color nodes and add colorbar
- Edge titles does not work? HOT 6
- Pyvis HTML Output does not use 100% of the page HOT 2
- Save as json
- Problem with labels, trying integration with pandas, Latex and Networkx
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvis.