Layout


In this section, you can learn how to get the list of available layout and how to apply it.

Table of contents


  • Get list of available layout
  • Apply layout
  • Fit an existing network view to current window

Network Data Preparation



In [2]:
# import data from url
from py2cytoscape.data.cyrest_client import CyRestClient
from IPython.display import Image
import json

# Create REST client for Cytoscape
cy = CyRestClient()

# Reset current session for fresh start
cy.session.delete()

# Load a sample network
network = cy.network.create_from('../sampleData/galFiltered.gml')

# Apply layout to the cytoscape network object
cy.layout.apply(network = network)

#Fit an existing network view to current window.
cy.layout.fit(network=network)

# Show it!!
Image(network.get_png(height=400))


Out[2]:

Get list of available layout



In [8]:
# Get list of available layout algorithms
layouts = cy.layout.get_all()
print(json.dumps(layouts, indent=4))


[
    "attribute-circle",
    "stacked-node-layout",
    "degree-circle",
    "circular",
    "attributes-layout",
    "kamada-kawai",
    "force-directed",
    "grid",
    "hierarchical",
    "fruchterman-rheingold",
    "isom",
    "force-directed-cl"
]

Apply layout



In [4]:
# Apply layout
cy.layout.apply(name='circular', network=network)

Fit an existing network view to current window


In [24]:
#Fit an existing network view to current window.
cy.layout.fit(network=network)