Skip to content

Instantly share code, notes, and snippets.

View joseberlines's full-sized avatar
💭
Python

joseberlines joseberlines

💭
Python
  • European Patent Office
  • Berlin
View GitHub Profile
@joseberlines
joseberlines / data1.py
Last active November 30, 2020 09:15
First Graph with ipycytoscape
railnet= '''{
"nodes": [
{"data": { "id": "BER" }},
{"data": { "id": "MUN"}},
{"data": { "id": "FRA"}},
{"data": { "id": "HAM"}}
],
"edges": [
{"data": { "source": "BER", "target": "MUN" }},
{"data": { "source": "MUN", "target": "FRA" }},
ipycytoscape_obj2 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj2.graph.add_graph_from_json(railnetJSON, directed=True)
ipycytoscape_obj2
railnet= '''{
"nodes": [
{"data": { "id": "BER", "label":"HBf BER"}},
{"data": { "id": "MUN", "label":"HBf MUN"}},
{"data": { "id": "FRA", "label":"HBf FRA"}},
{"data": { "id": "HAM", "label":"HBf HAM"}}
],
"edges": [
{"data": { "source": "BER", "target": "MUN" }},
{"data": { "source": "MUN", "target": "FRA" }},
my_style = [
{'selector': 'node','style': {
'font-family': 'helvetica',
'font-size': '20px',
'label': 'data(label)'}},
]
ipycytoscape_obj5 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj5.graph.add_graph_from_json(railnetJSON, directed=False)
ipycytoscape_obj5.set_style(my_style)
ipycytoscape_obj5
my_style = [
{'selector': 'node','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)',
'background-color': 'red'}},
]
ipycytoscape_obj6 = ipycytoscape.CytoscapeWidget()
ipycytoscape_obj6.graph.add_graph_from_json(railnetJSON, directed=False) # I am telling I dont want directions
ipycytoscape_obj6.set_style(my_style)
my_style = [
{'selector': 'node','style': {
'font-family': 'arial',
'font-size': '10px',
'label': 'data(label)',
'background-color': 'red'}},
{'selector': 'node[id = "BER"]','style': {
'font-family': 'arial',
'font-size': '10px',
railnet= '''{
"nodes": [
{"data": { "id": "BER", "label":"HBf BER"}},
{"data": { "id": "MUN", "label":"HBf MUN"}},
{"data": { "id": "FRA", "label":"HBf FRA"}},
{"data": { "id": "HAM", "label":"HBf HAM"}}
],
"edges": [
{"data": { "id": "line1", "source": "BER", "target": "MUN","label":"200km/h"}},
{"data": { "id": "line2", "source": "MUN", "target": "FRA","label":"200km/h"}},
railnet= '''{
"nodes": [
{"data": { "id": "BER", "label":"HBf BER", "classes":"east"}},
{"data": { "id": "MUN", "label":"HBf MUN", "classes":"west"}},
{"data": { "id": "FRA", "label":"HBf FRA", "classes":"west"}},
{"data": { "id": "HAM", "label":"HBf HAM", "classes":"west"}},
{"data": { "id": "LEP", "label":"HBf LEP", "classes":"east"}}
],
"edges": [
{"data": { "id": "line1", "source": "BER", "target": "MUN","label":"200km/h"}},
import ipycytoscape
import json
import ipywidgets
# I paste here allthe data in order to allow you to copy and paste it without loading data from files.
railnet= '''{
"nodes": [
{"data": { "id": "BER", "label":"HBf BER", "classes":"east"}},
{"data": { "id": "MUN", "label":"HBf MUN", "classes":"west"}},
{"data": { "id": "FRA", "label":"HBf FRA", "classes":"west"}},
{"data": { "id": "HAM", "label":"HBf HAM", "classes":"west"}},