py4cytoscape.network_views.export_image

export_image(filename=None, type='PNG', resolution=None, units=None, height=None, width=None, zoom=None, network=None, base_url='http://127.0.0.1:1234/v1', *, overwrite_file=False)[source]

Save the current network view as an image file.

The image is cropped per the current view in Cytoscape. Consider applying fit_content() prior to export.

Parameters
  • filename (str) – Full path or path relative to current working directory, in addition to the name of the file. Extension is automatically added based on the type argument. If blank, the current network name will be used.

  • type (str) – Type of image to export, e.g., PNG (default), JPEG, PDF, SVG, PS (PostScript).

  • resolution (int) – The resolution of the exported image, in DPI. Valid only for bitmap formats, when the selected width and height ‘units’ is inches. The possible values are: 72 (default), 100, 150, 300, 600.

  • units (str) – The possible values are: pixels (default), inches.

  • height (float) – The height of the exported image. Valid only for bitmap formats, such as PNG and JPEG.

  • width (float) – The width of the exported image. Valid only for bitmap formats, such as PNG and JPEG.

  • zoom (float) – The zoom value to proportionally scale the image. The default value is 100.0. Valid only for bitmap formats, such as PNG and JPEG

  • network (str or SUID or None) – Name or SUID of the network or view. Default is the “current” network active in Cytoscape. If a network view SUID is provided, then it is validated and returned.

  • 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.

  • overwrite_file (bool) – False allows Cytoscape show a message box before overwriting the file if the file already exists; True allows Cytoscape to overwrite it without asking

Returns

{‘file’: name of file} contains absolute path to file that was written

Return type

dict

Raises
  • CyError – if network or view doesn’t exist, or if file exists and user opts to not overwrite it

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

Examples

>>> export_image('output/test', type='JPEG', units='pixels', height=1000, width=2000, zoom=200)
{'file': 'C:\Users\CyDeveloper\tests\output\test.jpeg'}
>>> export_image('output/test', type='PDF', network='My Network')
{'file': 'C:\Users\CyDeveloper\tests\output\test.pdf'}
>>> export_image('output/test', type='PDF', overwrite_file=True) # overwrite any existing test.pdf
{'file': 'C:\Users\CyDeveloper\tests\output\test.pdf'}
>>> export_image(type='PNG', resolution=600, units='inches', height=1.7, width=3.5, zoom=500, network=13098)
{'file': 'C:\Users\CyDeveloper\tests\output\test.png'}