py4cytoscape.styles.create_visual_style

create_visual_style(style_name, defaults=None, mappings=None, base_url='http://127.0.0.1:1234/v1')[source]

Create a style from defaults and predefined mappings.

Requires visual property mappings to be previously created, see map_visual_property.

Parameters
  • style_name (str) – name for style

  • defaults (dict or list) – for dict, key-value pairs for default mappings. for list, [{‘visualProperty’: prop-name, ‘value’: default-val}, …]

  • mappings (list) – visual property mappings, see map_visual_property

  • base_url (str) – Ignore unless you need to specify a custom domain, port or version to connect to the CyREST API. Default is http://127.0.0.1:1234 and the latest version of the CyREST API supported by this version of py4cytoscape.

Returns

{‘title’: new style name}

Return type

dict

Raises
  • CyError – if mappings or defaults contain invalid values

  • requests.exceptions.RequestException – if can’t connect to Cytoscape or Cytoscape returns an error

Examples

>>> defaults = {'NODE_SHAPE': 'diamond', 'NODE_SIZE': 30, 'EDGE_TRANSPARENCY': 120, 'NODE_LABEL_POSITION': 'W,E,c,0.00,0.00'}
>>> node_labels = map_visual_property('node label', 'COMMON', 'p')
>>> node_fills = map_visual_property('node fill color', 'Degree', 'd', ['1', '2'], ['#FF9900', '#66AAAA'])
>>> arrow_shapes = map_visual_property('Edge Target Arrow Shape', 'interaction', 'd', ['pp', 'pd'], ['Arrow', 'T'])
>>> edge_width = map_visual_property('edge width', 'EdgeBetweenness', 'p')
>>> create_visual_style('NewStyle', defaults=defaults, mappings=[node_labels, node_fills, arrow_shapes, edge_width])
{'title': 'NewStyle'}
>>> defaults = [{'visualProperty': 'NODE_SHAPE', 'value': 'diamond'}, {'visualProperty': 'NODE_SIZE', 'value': 30}]
>>> create_visual_style('NewStyle1', defaults=defaults)
{'title': 'NewStyle1'}

Note

To apply the style to a network, first create the network and then call set_visual_style

This function can be used directly with the defaults and mappings members returned by get_visual_style_JSON

See also

map_visual_property(), set_visual_style(), get_visual_style_JSON()