Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interactive _standalone_ output from matplotlib

I like the plots matplotlib creates and the option to save them as SVG is great but...

I would like to be able to save the figure as SVG accompanied by javascript code that would add some level of interactivity. Eg. for each data sample in a scatter plot I would like to display some information in a tooltip. Is there a way to achieve this? Or how would you accomplish such a thing?

like image 439
tsh Avatar asked Oct 06 '11 08:10

tsh


People also ask

Can you make interactive plots in Python?

Overall, if you are getting started with interactive plots using Python, Plotly can be a good choice to create simple plots with limited interactive components. But if you are looking to add a number of interactive components to your plots, then Altair is something you should really try your hands on.

What does matplotlib use (' AGG ') do?

The last, Agg, is a non-interactive backend that can only write to files. It is used on Linux, if Matplotlib cannot connect to either an X display or a Wayland display.

What is interactive mode in matplotlib?

Matplotlib can be used in an interactive or non-interactive modes. In the interactive mode, the graph display gets updated after each statement. In the non-interactive mode, the graph does not get displayed until explicitly asked to do so.


1 Answers

This is fairly straightforward using Cytoscape.
What you need to do is create two files

  1. File containing node and edge information (File1)
  2. File containing tooltip information (File2)

File1

This just needs to be 3 columns (sourceNode, destinationNode, edgeLabel) And then you can go File→Import→Network from Table (Text/MS Excel).. Select the source node, destination node, and interaction type.

Remember to change the display options in the VizMapper

File2

Node and edge attribute files are simply formatted: a node attribute file begins with the name of the attribute on the first line (note that it cannot contain spaces). Each following line contains the name of the node, followed by an equals sign and the value of that attribute. Numbers and text strings are the most common attribute types. All values for a given attribute must have the same type. For example:

FunctionalCategory
YAL001C = metabolism
YAR002W = apoptosis
YBL007C = ribosome

An edge attribute file has much the same structure, except that the name of the edge is the source node name, followed by the interaction type in parentheses, followed by the target node name. Directionality counts, so switching the source and target will refer to a different (or perhaps non-existent) edge. The following is an example edge attributes file:

InteractionStrength
YAL001C (pp) YBR043W = 0.82
YMR022W (pd) YDL112C = 0.441
YDL112C (pd) YMR022W = 0.9013

Since Cytoscape treats edge attributes as directional, the second and third edge attribute values refer to two different edges (source and target are reversed, though the nodes involved are the same).

Each attribute is stored in a separate file. Node and edge attribute files use the same format. Node attribute file names often use the suffix ".noa", while edge attribute file names use the suffix ".eda". Cytoscape recognizes these suffixes when browsing for attribute files.

Node and edge attributes may be loaded at the command line using the –n and –e options or via the File → Import menu.

When expression data is loaded using an expression matrix, it is automatically loaded as node attribute data unless explicitly specified otherwise.

Node and edge attributes are attached to nodes and edges, and so are independent of networks. Attributes for a given node or edge will be applied to all copies of that node or edge in all loaded network files, regardless of whether the attribute file or network file is imported first.

Note: In order to import network attributes in Cytoscape 2.4, please go to File → Import → Attribute from Table (text/MS Excel)... or encode them in an XGMML network file

Every line past the first line identifies the name of an object (a node in a node attribute file or an edge in a edge attribute file) along with the String representation of the attribute value. The delimiter is always an equals sign; whitespace (spaces and/or tabs) before and after the equals sign is ignored.

Object names must be the Node ID or Edge ID as seen in the left-most column of the attribute browser if the attribute is to map to anything. These names must be reproduced exactly, including case, or they will not match.

Read this for more detail

like image 156
Lelouch Lamperouge Avatar answered Sep 21 '22 23:09

Lelouch Lamperouge