from py2cytoscape.data.cyrest_client import CyRestClient
cy = CyRestClient(ip='127.0.0.1', port=1234)
# 現在のセッションのクリア
cy.session.delete()
import networkx as nx
g = nx.scale_free_graph(500)
deg = nx.degree(g)
btw = nx.betweenness_centrality(g)
nx.set_node_attributes(g, 'degree', deg)
nx.set_node_attributes(g, 'betweenness', btw)
g_cy = cy.network.create_from_networkx(g)
cy.layout.apply(name='kamada-kawai', network=g_cy)
directed = cy.style.create('Directed')
cy.style.apply(directed, network=g_cy)
result = cy.edgebundling.apply(g_cy)
network_png = g_cy.get_png()
from IPython.display import Image
Image(network_png)
network_svg = g_cy.get_svg()
from IPython.display import SVG
SVG(network_svg)
network_pdf = g_cy.get_pdf()
# ファイルに保存
f = open('scale_free_500.pdf', 'wb')
f.write(network_pdf)
f.close()
import py2cytoscape.cytoscapejs as renderer
view = g_cy.get_first_view()
# style_for_widget = cy.style.get(my_yeast_style.get_name(), data_format='cytoscapejs')
renderer.render(view, 'Directed', background='radial-gradient(#FFFFFF 15%, #DDDDDD 105%)')